Color   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 9
c 1
b 0
f 1
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 1
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\Builder;
15
use Illuminate\Support\Facades\Cache;
16
17
/**
18
 * Turahe\Master\Color.
19
 *
20
 * @property int    $id
21
 * @property string $name
22
 * @property string $code
23
 *
24
 * @method static Builder|Color newModelQuery()
25
 * @method static Builder|Color newQuery()
26
 * @method static Builder|Color query()
27
 * @method static Builder|Color whereCode($value)
28
 * @method static Builder|Color whereId($value)
29
 * @method static Builder|Color whereName($value)
30
 * @mixin \Eloquent
31
 */
32
class Color extends Model
33
{
34
    protected $table = 'tm_colors';
35
36
    /**
37
     * @inheritDoc
38
     */
39
    protected static function boot()
40
    {
41
        parent::boot();
42
43
        static::addGlobalScope('alphabetical', function (Builder $builder) {
44
            $builder->orderBy('name', 'asc');
45
        });
46
        static::updating(function ($instance) {
47
            Cache::put('colors.'.$instance->slug, $instance);
48
        });
49
        static::deleting(function ($instance) {
50
            Cache::delete('colors.'.$instance->slug);
51
        });
52
    }
53
}
54