1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Address; |
4
|
|
|
|
5
|
|
|
use Yajra\Address\Entities\Barangay; |
6
|
|
|
use Yajra\Address\Entities\City; |
7
|
|
|
use Yajra\Address\Entities\Province; |
8
|
|
|
use Yajra\Address\Entities\Region; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @property string street |
12
|
|
|
* @property Region region |
13
|
|
|
* @property Province province |
14
|
|
|
* @property City city |
15
|
|
|
* @property Barangay barangay |
16
|
|
|
*/ |
17
|
|
|
trait HasAddress |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
21
|
|
|
*/ |
22
|
|
|
public function region() |
23
|
|
|
{ |
24
|
|
|
return $this->belongsTo(Region::class, 'region_id', 'region_id'); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
29
|
|
|
*/ |
30
|
|
|
public function province() |
31
|
|
|
{ |
32
|
|
|
return $this->belongsTo(Province::class, 'province_id', 'province_id'); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
37
|
|
|
*/ |
38
|
|
|
public function city() |
39
|
|
|
{ |
40
|
|
|
return $this->belongsTo(City::class, 'city_id', 'city_id'); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
45
|
|
|
*/ |
46
|
|
|
public function barangay() |
47
|
|
|
{ |
48
|
|
|
return $this->belongsTo(Barangay::class, 'barangay_id', 'code'); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getAddressAttribute() |
55
|
|
|
{ |
56
|
|
|
return sprintf("%s %s, %s, %s", |
57
|
|
|
$this->street, |
58
|
|
|
$this->barangay->description, |
59
|
|
|
$this->city->description, |
60
|
|
|
$this->province->description |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.