|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Shop\Addresses; |
|
4
|
|
|
|
|
5
|
|
|
use App\Shop\Customers\Customer; |
|
6
|
|
|
use App\Shop\Orders\Order; |
|
7
|
|
|
use App\Shop\Provinces\Province; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
9
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
10
|
|
|
use App\Shop\Cities\City; |
|
11
|
|
|
use App\Shop\Countries\Country; |
|
12
|
|
|
use Nicolaslopezj\Searchable\SearchableTrait; |
|
13
|
|
|
|
|
14
|
|
|
class Address extends Model |
|
15
|
|
|
{ |
|
16
|
|
|
use SoftDeletes, SearchableTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The attributes that are mass assignable. |
|
20
|
|
|
* |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
public $fillable = [ |
|
24
|
|
|
'alias', |
|
25
|
|
|
'address_1', |
|
26
|
|
|
'address_2', |
|
27
|
|
|
'zip', |
|
28
|
|
|
'city', |
|
29
|
|
|
'state_code', |
|
30
|
|
|
'province_id', |
|
31
|
|
|
'country_id', |
|
32
|
|
|
'customer_id', |
|
33
|
|
|
'status', |
|
34
|
|
|
'phone' |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The attributes that should be hidden for arrays. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $hidden = []; |
|
43
|
|
|
|
|
44
|
|
|
protected $dates = ['deleted_at']; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Searchable rules. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $searchable = [ |
|
52
|
|
|
'columns' => [ |
|
53
|
|
|
'alias' => 5, |
|
54
|
|
|
'address_1' => 10, |
|
55
|
|
|
'address_2' => 5, |
|
56
|
|
|
'zip' => 5, |
|
57
|
|
|
'city' => 10, |
|
58
|
|
|
'state_code' => 10, |
|
59
|
|
|
'phone' => 5 |
|
60
|
|
|
] |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
public function customer() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->belongsTo(Customer::class); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function country() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->belongsTo(Country::class); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function province() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->belongsTo(Province::class); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @deprecated |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
82
|
|
|
*/ |
|
83
|
|
|
public function city() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->belongsTo(City::class, 'city'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
90
|
|
|
*/ |
|
91
|
|
|
public function orders() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->hasMany(Order::class); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param $term |
|
98
|
|
|
* |
|
99
|
|
|
* @return mixed |
|
100
|
|
|
*/ |
|
101
|
|
|
public function searchAddress($term) |
|
102
|
|
|
{ |
|
103
|
|
|
return self::search($term); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|