Role::users()   A
last analyzed

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 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