1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PWWEB\Localisation\Models\Tax; |
4
|
|
|
|
5
|
|
|
use Eloquent as Model; |
6
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
8
|
|
|
use PWWEB\Core\Traits\Migratable; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* PWWEB\Localisation\Models\Tax\Location Model. |
12
|
|
|
* |
13
|
|
|
* Standard Location Model. |
14
|
|
|
* |
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 \PWWEB\Localisation\Models\SystemLocalisationCountry country |
20
|
|
|
* @property PWWEB\Localisation\Models\Tax\Rate $taxRate |
21
|
|
|
* @property foreignId $country_id |
22
|
|
|
* @property foreignId $tax_rate_id |
23
|
|
|
* @property string $state |
24
|
|
|
* @property string $city |
25
|
|
|
* @property string $zip |
26
|
|
|
* @property unsignedTinyInteger $order |
27
|
|
|
*/ |
28
|
|
|
class Location extends Model |
29
|
|
|
{ |
30
|
|
|
use Migratable; |
31
|
|
|
use SoftDeletes; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The attributes that should be casted to Carbon dates. |
35
|
|
|
* |
36
|
|
|
* @var string[] |
37
|
|
|
*/ |
38
|
|
|
protected $dates = [ |
39
|
|
|
'deleted_at', |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The attributes that can be filled. |
44
|
|
|
* |
45
|
|
|
* @var string[] |
46
|
|
|
*/ |
47
|
|
|
public $fillable = [ |
48
|
|
|
'country_id', |
49
|
|
|
'tax_rate_id', |
50
|
|
|
'state', |
51
|
|
|
'city', |
52
|
|
|
'zip', |
53
|
|
|
'order', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The attributes that should be casted to native types. |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
protected $casts = [ |
62
|
|
|
'state' => 'string', |
63
|
|
|
'city' => 'string', |
64
|
|
|
'zip' => 'string', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Validation rules. |
69
|
|
|
* |
70
|
|
|
* @var array |
71
|
|
|
*/ |
72
|
|
|
public static $rules = [ |
73
|
|
|
'country_id' => 'required', |
74
|
|
|
'tax_rate_id' => 'required', |
75
|
|
|
'order' => 'required', |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Constructor. |
80
|
|
|
* |
81
|
|
|
* @param array $attributes additional attributes for model initialisation |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function __construct(array $attributes = []) |
86
|
|
|
{ |
87
|
|
|
parent::__construct($attributes); |
88
|
|
|
|
89
|
|
|
$this->setTable(config('pwweb.localisation.table_names.tax.locations')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Accessor for linked Country model. |
94
|
|
|
* |
95
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
96
|
|
|
**/ |
97
|
|
|
public function country(): BelongsTo |
98
|
|
|
{ |
99
|
|
|
return $this->belongsTo(config('pwweb.localisation.models.country'), 'country_id'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Accessor for linked Tax Rate model. |
104
|
|
|
* |
105
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
106
|
|
|
**/ |
107
|
|
|
public function rate(): BelongsTo |
108
|
|
|
{ |
109
|
|
|
return $this->belongsTo(config('pwweb.localisation.models.tax.rate'), 'tax_rate_id'); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|