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