Issues (52)

src/Models/Village.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Turahe\Master\Models;
4
5
use Illuminate\Database\Eloquent\Relations\BelongsTo;
6
use Illuminate\Support\Facades\Cache;
7
8
/**
9
 * Class Village.
10
 *
11
 * @property null|string district
12
 * @property null|string name
13
 * @mixin \Eloquent
14
 */
15
class Village extends Model
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $table = 'tm_villages';
21
22
    /**
23
     * @var string[]
24
     */
25
    protected $casts = [
26
        'meta' => 'array',
27
    ];
28
29
    /**
30
     * Bootstrap the model and its traits.
31
     *
32
     * Caching model when updating and
33
     * delete cache when delete models
34
     *
35
     * @return void
36
     */
37
    protected static function boot()
38
    {
39
        parent::boot(); // TODO: Change the autogenerated stub
40
        static::updating(function ($instance) {
41
            Cache::put('villages.'.$instance->slug, $instance);
42
        });
43
        static::deleting(function ($instance) {
44
            Cache::delete('villages.'.$instance->slug);
45
        });
46
    }
47
48
    /**
49
     * @return BelongsTo
50
     */
51
    public function district(): BelongsTo
52
    {
53
        return $this->belongsTo(District::class, 'district_id');
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getDistrictNameAttribute()
60
    {
61
        return $this->district->name;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function getCityNameAttribute()
68
    {
69
        return $this->district->city->name;
70
    }
71
72
    /**
73
     * @return mixed
74
     */
75
    public function getProvinceNameAttribute()
76
    {
77
        return $this->district->city->province->name;
0 ignored issues
show
The property province does not seem to exist on Turahe\Master\Models\City. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getAddressAttribute()
84
    {
85
        return sprintf(
86
            '%s, %s, %s, %s, Indonesia',
87
            $this->name,
88
            $this->district->name,
89
            $this->district->city->name,
90
            $this->district->city->province->name
0 ignored issues
show
The property province does not seem to exist on Turahe\Master\Models\City. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
91
        );
92
    }
93
}
94