Total Complexity | 6 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
16 | class District extends Model |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $table = 'tm_districts'; |
||
22 | |||
23 | /** |
||
24 | * @var string[] |
||
25 | */ |
||
26 | protected $casts = [ |
||
27 | 'meta' => 'array', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Bootstrap the model and its traits. |
||
32 | * |
||
33 | * Caching model when updating and |
||
34 | * delete cache when delete models |
||
35 | * |
||
36 | * @return void |
||
37 | */ |
||
38 | protected static function boot() |
||
39 | { |
||
40 | parent::boot(); // TODO: Change the autogenerated stub |
||
41 | static::updating(function ($instance) { |
||
42 | Cache::put('districts.'.$instance->slug, $instance); |
||
43 | }); |
||
44 | static::deleting(function ($instance) { |
||
45 | Cache::delete('districts.'.$instance->slug); |
||
46 | }); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return BelongsTo |
||
51 | */ |
||
52 | public function city(): BelongsTo |
||
53 | { |
||
54 | return $this->belongsTo(City::class, 'city_id'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @return HasMany |
||
59 | */ |
||
60 | public function villages(): HasMany |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function getCityNameAttribute() |
||
69 | { |
||
70 | return $this->city->name; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return mixed |
||
75 | */ |
||
76 | public function getProvinceNameAttribute() |
||
77 | { |
||
78 | return $this->city->province->name; |
||
|
|||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getAddressAttribute(): string |
||
91 | ); |
||
92 | } |
||
93 | } |
||
94 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.