Completed
Push — master ( 5bcf34...65b760 )
by Freek
01:53
created

bootRefreshesPermissionCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 14
rs 9.4285
1
<?php
2
3
namespace Spatie\Permission\Traits;
4
5
use Spatie\Permission\PermissionRegistrar;
6
7
trait RefreshesPermissionCache
8
{
9
    public static function bootRefreshesPermissionCache()
10
    {
11
        static::created(function ($model) {
12
            $model->forgetCachedPermissions();
13
        });
14
15
        static::updated(function ($model) {
16
            $model->forgetCachedPermissions();
17
        });
18
19
        static::deleted(function ($model) {
20
            $model->forgetCachedPermissions();
21
        });
22
    }
23
24
    /**
25
     *  Forget the cached permissions.
26
     */
27
    public function forgetCachedPermissions()
28
    {
29
        app(PermissionRegistrar::class)->forgetCachedPermissions();
30
    }
31
32
    /**
33
     * Get the current cached permissions.
34
     *
35
     * @return \Illuminate\Database\Eloquent\Collection
36
     */
37
    protected static function getPermissions()
38
    {
39
        return app(PermissionRegistrar::class)->getPermissions();
40
    }
41
}
42