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 = ['deleted_at']; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The attributes that can be filled. |
42
|
|
|
* |
43
|
|
|
* @var string[] |
44
|
|
|
*/ |
45
|
|
|
public $fillable = [ |
46
|
|
|
'country_id', |
47
|
|
|
'tax_rate_id', |
48
|
|
|
'state', |
49
|
|
|
'city', |
50
|
|
|
'zip', |
51
|
|
|
'order', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The attributes that should be casted to native types. |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
protected $casts = [ |
60
|
|
|
'state' => 'string', |
61
|
|
|
'city' => 'string', |
62
|
|
|
'zip' => 'string', |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Validation rules. |
67
|
|
|
* |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
public static $rules = [ |
71
|
|
|
'country_id' => 'required', |
72
|
|
|
'tax_rate_id' => 'required', |
73
|
|
|
'order' => 'required', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Constructor. |
78
|
|
|
* |
79
|
|
|
* @param array $attributes additional attributes for model initialisation |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function __construct(array $attributes = []) |
84
|
|
|
{ |
85
|
|
|
parent::__construct($attributes); |
86
|
|
|
|
87
|
|
|
$this->setTable(config('pwweb.localisation.table_names.tax.locations')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Accessor for linked Country model. |
92
|
|
|
* |
93
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
94
|
|
|
**/ |
95
|
|
|
public function country(): BelongsTo |
96
|
|
|
{ |
97
|
|
|
return $this->belongsTo(\PWWEB\Localisation\Models\Country::class, 'country_id'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Accessor for linked Tax Rate model. |
102
|
|
|
* |
103
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
104
|
|
|
**/ |
105
|
|
|
public function rate(): BelongsTo |
106
|
|
|
{ |
107
|
|
|
return $this->belongsTo(\PWWEB\Localisation\Models\Tax\Rate::class, 'tax_rate_id'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|