Completed
Push — master ( 1af3cf...ff825a )
by Arjay
27:57 queued 13:02
created

Role   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 37
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findBySlug() 0 4 1
A users() 0 5 1
1
<?php
2
3
namespace Yajra\Acl\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
7
use Yajra\Acl\Traits\HasPermission;
8
use Yajra\Acl\Traits\RefreshCache;
9
10
/**
11
 * @property bool system
12
 */
13
class Role extends Model
14
{
15
    use HasPermission, RefreshCache;
16
17
    /** @var string */
18
    protected $table = 'roles';
19
20
    /** @var array */
21
    protected $fillable = ['name', 'slug', 'description', 'system'];
22
23
    /** @var array */
24
    protected $casts = [
25
        'system' => 'bool',
26
    ];
27
28
    /**
29
     * Find a role by slug.
30
     *
31
     * @param  string  $slug
32
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
33
     */
34
    public static function findBySlug(string $slug)
35
    {
36
        return static::query()->where('slug', $slug)->firstOrFail();
37
    }
38
39
    /**
40
     * Roles can belong to many users.
41
     *
42
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
43
     */
44
    public function users(): BelongsToMany
45
    {
46
        return $this->belongsToMany(config('acl.user', config('auth.providers.users.model')))
47
            ->withTimestamps();
48
    }
49
}
50