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:06 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\City. |
19
|
|
|
* |
20
|
|
|
* @property int $id |
21
|
|
|
* @property string $name |
22
|
|
|
* @property null|string $postal_code |
23
|
|
|
* @property null|string $latitude |
24
|
|
|
* @property null|string $longitude |
25
|
|
|
* @property int $state_id |
26
|
|
|
* @property null|\Illuminate\Support\Carbon $created_at |
27
|
|
|
* @property null|\Illuminate\Support\Carbon $updated_at |
28
|
|
|
* @property-read \Turahe\Master\Models\State $state |
29
|
|
|
* |
30
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City newModelQuery() |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City newQuery() |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City query() |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereCreatedAt($value) |
34
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereId($value) |
35
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereLatitude($value) |
36
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereLongitude($value) |
37
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereName($value) |
38
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City wherePostalCode($value) |
39
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereStateId($value) |
40
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|City whereUpdatedAt($value) |
41
|
|
|
* @mixin \Eloquent |
42
|
|
|
*/ |
43
|
|
|
class City extends Model |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
|
|
protected $table = 'tm_cities'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Bootstrap the model and its traits. |
52
|
|
|
* |
53
|
|
|
* Caching model when updating and |
54
|
|
|
* delete cache when delete models |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected static function boot() |
59
|
|
|
{ |
60
|
|
|
parent::boot(); // TODO: Change the autogenerated stub |
61
|
|
|
static::updating(function ($instance) { |
62
|
|
|
Cache::put('cities.'.$instance->slug, $instance); |
63
|
|
|
}); |
64
|
|
|
static::deleting(function ($instance) { |
65
|
|
|
Cache::delete('cities.'.$instance->slug); |
66
|
|
|
}); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Return the city's state. |
71
|
|
|
* |
72
|
|
|
* @return BelongsTo |
73
|
|
|
*/ |
74
|
|
|
public function state(): BelongsTo |
75
|
|
|
{ |
76
|
|
|
return $this->belongsTo(State::class); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|