State::country()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
dl 0
loc 3
c 1
b 0
f 1
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * For the full copyright and license information, please view the LICENSE
4
 * file that was distributed with this source code.
5
 *
6
 * @modified    8/11/20, 8:08 PM
7
 *  @name          toko
8
 * @author         Wachid
9
 * @copyright      Copyright (c) 2019-2020.
10
 */
11
12
namespace Turahe\Master\Models;
13
14
use Illuminate\Database\Eloquent\Relations\BelongsTo;
15
use Illuminate\Support\Facades\Cache;
16
17
/**
18
 * Turahe\Master\State.
19
 *
20
 * @property-read \Turahe\Master\Models\Country $country
21
 *
22
 * @method static \Illuminate\Database\Eloquent\Builder|State newModelQuery()
23
 * @method static \Illuminate\Database\Eloquent\Builder|State newQuery()
24
 * @method static \Illuminate\Database\Eloquent\Builder|State query()
25
 * @mixin \Eloquent
26
 *
27
 * @property int                             $id
28
 * @property int                             $country_id
29
 * @property string                          $country_name
30
 * @property string                          $name
31
 * @property null|string                     $region
32
 * @property null|string                     $iso_3166_2
33
 * @property null|string                     $region_code
34
 * @property null|string                     $calling_code
35
 * @property int                             $active
36
 * @property null|\Illuminate\Support\Carbon $created_at
37
 * @property null|\Illuminate\Support\Carbon $updated_at
38
 *
39
 * @method static \Illuminate\Database\Eloquent\Builder|State whereActive($value)
40
 * @method static \Illuminate\Database\Eloquent\Builder|State whereCallingCode($value)
41
 * @method static \Illuminate\Database\Eloquent\Builder|State whereCountryId($value)
42
 * @method static \Illuminate\Database\Eloquent\Builder|State whereCountryName($value)
43
 * @method static \Illuminate\Database\Eloquent\Builder|State whereCreatedAt($value)
44
 * @method static \Illuminate\Database\Eloquent\Builder|State whereId($value)
45
 * @method static \Illuminate\Database\Eloquent\Builder|State whereIso31662($value)
46
 * @method static \Illuminate\Database\Eloquent\Builder|State whereName($value)
47
 * @method static \Illuminate\Database\Eloquent\Builder|State whereRegion($value)
48
 * @method static \Illuminate\Database\Eloquent\Builder|State whereRegionCode($value)
49
 * @method static \Illuminate\Database\Eloquent\Builder|State whereUpdatedAt($value)
50
 */
51
class State extends Model
52
{
53
    protected $table = 'tm_states';
54
    /**
55
     * The attributes that are mass assignable.
56
     *
57
     * @var array
58
     */
59
    public $fillable = [
60
        'name',
61
        'state_code',
62
    ];
63
64
    /**
65
     * Bootstrap the model and its traits.
66
     *
67
     * Caching model when updating and
68
     * delete cache when delete models
69
     *
70
     * @return void
71
     */
72
    protected static function boot()
73
    {
74
        parent::boot(); // TODO: Change the autogenerated stub
75
        static::updating(function ($instance) {
76
            Cache::put('states.'.$instance->slug, $instance);
77
        });
78
        static::deleting(function ($instance) {
79
            Cache::delete('states.'.$instance->slug);
80
        });
81
    }
82
83
    /**
84
     * @return BelongsTo
85
     */
86
    public function country(): BelongsTo
87
    {
88
        return $this->belongsTo(Country::class);
89
    }
90
}
91