Passed
Push — master ( f1a782...17ae54 )
by Ion
04:19 queued 45s
created

Permission   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 30
c 1
b 0
f 1
dl 0
loc 69
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A roles() 0 11 1
A rolePermissions() 0 3 1
1
<?php
2
3
namespace App\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8
use Illuminate\Database\Eloquent\Relations\HasMany;
9
use Illuminate\Database\Eloquent\SoftDeletes;
10
11
/**
12
 * Class Permission
13
 *
14
 * @property int $id
15
 * @property string $name
16
 * @property Carbon|null $created_at
17
 * @property Carbon|null $updated_at
18
 * @property Carbon|null $deleted_at
19
 *
20
 * @property-read Collection|Role[] $roles
21
 * @property-read Collection|RolePermission[] $rolePermissions
22
 *
23
 * @package App\Models
24
 */
25
class Permission extends Model
26
{
27
    use SoftDeletes;
28
29
    /** @var int */
30
    const ID_USERS = 1;
31
32
    /** @var int */
33
    const ID_ROLES = 2;
34
35
    /** @var int */
36
    const ID_TASKS = 3;
37
38
    /** @var bool */
39
    public $timestamps = true;
40
41
    /** @var string */
42
    protected $table = 'permissions';
43
44
    /** @var array */
45
    protected $fillable = [
46
        'name'
47
    ];
48
49
    /** @var array */
50
    protected $visible = [
51
        'id',
52
        'name',
53
        'roles',
54
        'access',
55
        'rolePermissions'
56
    ];
57
58
    /** @var array */
59
    protected $sortable = [
60
        'id',
61
        'name'
62
    ];
63
64
    /** @var array */
65
    protected $searchable = [
66
        'name'
67
    ];
68
69
    /**
70
     * @return BelongsToMany
71
     */
72
    public function roles()
73
    {
74
        return $this->belongsToMany(Role::class, 'role_permissions', 'permission_id', 'role_id')
75
            ->as('access')
76
            ->using(RolePermission::class)
77
            ->withPivot([
78
                'read',
79
                'create',
80
                'update',
81
                'delete',
82
                'manage'
83
            ]);
84
    }
85
86
    /**
87
     * Role permissions.
88
     *
89
     * @return HasMany
90
     */
91
    public function rolePermissions()
92
    {
93
        return $this->hasMany(RolePermission::class, 'permission_id', 'id');
94
    }
95
}
96