1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PWWEB\Localisation\Models; |
4
|
|
|
|
5
|
|
|
use Eloquent as Model; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* App\Models\Pwweb\Localisation\Models\Country Model. |
9
|
|
|
* |
10
|
|
|
* Standard Country Model. |
11
|
|
|
* |
12
|
|
|
* @package pwweb/localisation |
13
|
|
|
* @author Frank Pillukeit <[email protected]> |
14
|
|
|
* @author Richard Browne <[email protected] |
15
|
|
|
* @copyright 2020 pw-websolutions.com |
16
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
17
|
|
|
* @property \Illuminate\Database\Eloquent\Collection addresses |
18
|
|
|
* @property \Illuminate\Database\Eloquent\Collection languages |
19
|
|
|
* @property string name |
20
|
|
|
* @property string iso |
21
|
|
|
* @property string ioc |
22
|
|
|
* @property boolean active |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
class Country extends Model |
26
|
|
|
{ |
27
|
|
|
const CREATED_AT = 'created_at'; |
28
|
|
|
const UPDATED_AT = 'updated_at'; |
29
|
|
|
|
30
|
|
|
public $fillable = [ |
31
|
|
|
'name', |
32
|
|
|
'iso', |
33
|
|
|
'ioc', |
34
|
|
|
'active' |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The attributes that should be casted to native types. |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $casts = [ |
43
|
|
|
'id' => 'integer', |
44
|
|
|
'name' => 'string', |
45
|
|
|
'iso' => 'string', |
46
|
|
|
'ioc' => 'string', |
47
|
|
|
'active' => 'boolean' |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Validation rules. |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
public static $rules = [ |
56
|
|
|
'name' => 'required', |
57
|
|
|
'iso' => 'required', |
58
|
|
|
'active' => 'required' |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Constructor. |
63
|
|
|
* |
64
|
|
|
* @param array $attributes additional attributes for model initialisation |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function __construct(array $attributes = []) |
69
|
|
|
{ |
70
|
|
|
parent::__construct($attributes); |
71
|
|
|
|
72
|
|
|
$this->setTable(config('pwweb.localisation.table_names.countries')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
77
|
|
|
**/ |
78
|
|
|
public function addresses() |
79
|
|
|
{ |
80
|
|
|
return $this->hasMany(\PWWEB\Localisation\Models\Address::class, 'country_id'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
85
|
|
|
**/ |
86
|
|
|
public function languages() |
87
|
|
|
{ |
88
|
|
|
return $this->belongsToMany(\PWWEB\Localisation\Models\Language::class, 'system_localisation_country_languages'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Obtain a localised country name. |
93
|
|
|
* |
94
|
|
|
* @param string $value Original value. |
95
|
|
|
* |
96
|
|
|
* @return string|array Localised country name. |
97
|
|
|
*/ |
98
|
|
|
public function getNameAttribute($value) |
99
|
|
|
{ |
100
|
|
|
if (null === $value || '' === $value) { |
101
|
|
|
return ''; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return __('pwweb::localisation.'.$value); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|