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

RefreshesPermissionCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 35
c 1
b 0
f 1
wmc 3
lcom 0
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forgetCachedPermissions() 0 4 1
A bootRefreshesPermissionCache() 0 14 1
A getPermissions() 0 4 1
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