1 | <?php |
||
2 | |||
3 | namespace Turahe\Master\Models; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Relations\HasMany; |
||
6 | use Illuminate\Database\Eloquent\Relations\HasManyThrough; |
||
7 | |||
8 | /** |
||
9 | * Class Province. |
||
10 | * |
||
11 | * @mixin \Eloquent |
||
12 | */ |
||
13 | class Province extends State |
||
14 | { |
||
15 | /** |
||
16 | * @return HasMany |
||
17 | */ |
||
18 | public function cities(): HasMany |
||
19 | { |
||
20 | return $this->hasMany(City::class, 'state_id'); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @return HasManyThrough |
||
25 | */ |
||
26 | public function districts(): HasManyThrough |
||
27 | { |
||
28 | return $this->hasManyThrough(District::class, City::class); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | public function getLogoPathAttribute() |
||
35 | { |
||
36 | $folder = 'indonesia-logo/'; |
||
37 | $id = $this->getAttributeValue('id'); |
||
38 | $arr_glob = glob(public_path().'/'.$folder.$id.'.*'); |
||
39 | if (count($arr_glob) == 1) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
40 | $logo_name = basename($arr_glob[0]); |
||
41 | $logo_path = url($folder.$logo_name); |
||
42 | |||
43 | return $logo_path; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getAddressAttribute(): string |
||
51 | { |
||
52 | return sprintf( |
||
53 | '%s, Indonesia', |
||
54 | $this->name |
||
55 | ); |
||
56 | } |
||
57 | } |
||
58 |