Permission   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setCanAttribute() 0 3 1
A cacheKey() 0 3 2
A boot() 0 10 1
A role() 0 3 1
A getActivitylogOptions() 0 3 1
1
<?php
2
3
namespace Pratiksh\Adminetic\Models\Admin;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Cache;
7
use Spatie\Activitylog\LogOptions;
8
use Spatie\Activitylog\Traits\LogsActivity;
9
10
class Permission extends Model
11
{
12
    use LogsActivity;
0 ignored issues
show
introduced by
The trait Spatie\Activitylog\Traits\LogsActivity requires some properties which are not provided by Pratiksh\Adminetic\Models\Admin\Permission: $submitEmptyLogs, $name, $logExceptAttributes, $attributeRawValues, $dontLogIfAttributesChangedOnly, $descriptionForEvent, $logOnlyDirty, $logFillable, $value, $logUnguarded, $logAttributes
Loading history...
13
14
    protected $guarded = [];
15
16
    // Mutators
17
    public function setCanAttribute($value)
18
    {
19
        return $this->attributes['can'] = strtolower(str_replace(' ', '-', $value));
20
    }
21
22
    // Forget cache on updating or saving and deleting
23
    public static function boot()
24
    {
25
        parent::boot();
26
27
        static::saving(function () {
28
            self::cacheKey();
29
        });
30
31
        static::deleting(function () {
32
            self::cacheKey();
33
        });
34
    }
35
36
    // Cache Keys
37
    private static function cacheKey()
38
    {
39
        Cache::has('permissions') ? Cache::forget('permissions') : '';
40
    }
41
42
    // Logs
43
    protected static $logName = 'permission';
44
45
    public function getActivitylogOptions(): LogOptions
46
    {
47
        return LogOptions::defaults();
48
    }
49
50
    // Relations
51
    public function role()
52
    {
53
        return $this->belongsTo(Role::class, 'role_id');
54
    }
55
}
56