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
![]() |
|||
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 |