Completed
Push — master ( 876e58...7fc0d0 )
by Arjay
18:23 queued 04:39
created

Role::users()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Yajra\Acl\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Yajra\Acl\Traits\HasPermission;
7
8
/**
9
 * @property \Yajra\Acl\Models\Permission permissions
10
 * @property bool system
11
 */
12
class Role extends Model
13
{
14
    use HasPermission;
15
16
    /**
17
     * The database table used by the model.
18
     *
19
     * @var string
20
     */
21
    protected $table = 'roles';
22
23
    /**
24
     * Fillable fields.
25
     *
26
     * @var array
27
     */
28
    protected $fillable = ['name', 'slug', 'description', 'system'];
29
30
    protected static function boot()
31
    {
32
        parent::boot();
33
34
        static::saved(function () {
35
            app('cache.store')->forget('permissions.policies');
36
        });
37
38
        static::deleted(function () {
39
            app('cache.store')->forget('permissions.policies');
40
        });
41
    }
42
43
    /**
44
     * Roles can belong to many users.
45
     *
46
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\BelongsToMany
47
     */
48
    public function users()
49
    {
50
        return $this->belongsToMany(config('acl.user', config('auth.providers.users.model')))
51
                    ->withTimestamps();
52
    }
53
}
54