Role   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
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 38
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

2 Methods

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