RolePermission::role()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Database\Eloquent\Relations\Pivot;
9
use IonGhitun\MysqlEncryption\Models\BaseModel;
10
11
/**
12
 * Class RolePermission
13
 *
14
 * @property int $id
15
 * @property int $role_id
16
 * @property int $permission_id
17
 * @property int $read
18
 * @property int $create
19
 * @property int $update
20
 * @property int $delete
21
 * @property int $manage
22
 * @property Carbon|null $created_at
23
 * @property Carbon|null $updated_at
24
 *
25
 * @property Role $role
26
 * @property Permission $permission
27
 *
28
 * @method static Builder|RolePermission newModelQuery()
29
 * @method static Builder|RolePermission newQuery()
30
 * @method static Builder|RolePermission query()
31
 * @method static Builder|RolePermission whereCreate($value)
32
 * @method static Builder|RolePermission whereCreatedAt($value)
33
 * @method static Builder|RolePermission whereDelete($value)
34
 * @method static Builder|RolePermission whereId($value)
35
 * @method static Builder|RolePermission whereManage($value)
36
 * @method static Builder|RolePermission wherePermissionId($value)
37
 * @method static Builder|RolePermission whereRead($value)
38
 * @method static Builder|RolePermission whereRoleId($value)
39
 * @method static Builder|RolePermission whereUpdate($value)
40
 * @method static Builder|RolePermission whereUpdatedAt($value)
41
 * @method static Builder|BaseModel orWhereEncrypted($column, $value)
42
 * @method static Builder|BaseModel orWhereNotEncrypted($column, $value)
43
 * @method static Builder|BaseModel orderByEncrypted($column, $direction)
44
 * @method static Builder|BaseModel whereEncrypted($column, $value)
45
 * @method static Builder|BaseModel whereNotEncrypted($column, $value)
46
 *
47
 * @package App\Models
48
 */
49
class RolePermission extends Pivot
50
{
51
    /** @var int */
52
    const PERMISSION_FALSE = 0;
53
54
    /** @var int */
55
    const PERMISSION_TRUE = 1;
56
57
    /** @var int */
58
    const MANAGE_OWN = 0;
59
60
    /** @var int */
61
    const MANAGE_ALL = 1;
62
63
    /** @var bool */
64
    public $incrementing = true;
65
66
    /** @var bool */
67
    public $timestamps = true;
68
69
    /** @var string */
70
    protected $table = 'role_permissions';
71
72
    /** @var array */
73
    protected $fillable = [
74
        'role_id',
75
        'permission_id',
76
        'read',
77
        'create',
78
        'update',
79
        'delete',
80
        'manage'
81
    ];
82
83
    /** @var array */
84
    protected $visible = [
85
        'id',
86
        'read',
87
        'create',
88
        'update',
89
        'delete',
90
        'manage',
91
        'role',
92
        'permission'
93
    ];
94
95
    /** @var array */
96
    protected $hidden = [
97
        'role_id',
98
        'permission_id'
99
    ];
100
101
    /** @var array */
102
    protected $casts = [
103
        'read'   => 'int',
104
        'create' => 'int',
105
        'update' => 'int',
106
        'delete' => 'int',
107
        'manage' => 'int',
108
    ];
109
110
    /**
111
     * Role.
112
     *
113
     * @return BelongsTo
114
     */
115
    public function role()
116
    {
117
        return $this->belongsTo(Role::class, 'role_id', 'id');
118
    }
119
120
    /**
121
     * Permission.
122
     *
123
     * @return BelongsTo
124
     */
125
    public function permission()
126
    {
127
        return $this->belongsTo(Permission::class, 'permission_id', 'id');
128
    }
129
}
130