1 | <?php |
||
9 | class Role extends Model |
||
10 | { |
||
11 | /** |
||
12 | * The table associated with the model. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $table; |
||
17 | |||
18 | /** |
||
19 | * The attributes that are mass assignable. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $fillable = ['name', 'client_id']; |
||
24 | |||
25 | /** |
||
26 | * The attributes that should be cast to native types. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $casts = ['locked' => 'boolean']; |
||
31 | |||
32 | /** |
||
33 | * Save a new model and return the instance. |
||
34 | * |
||
35 | * @param array $attributes |
||
36 | * @return static |
||
37 | */ |
||
38 | public static function create(array $attributes = []) |
||
45 | |||
46 | /** |
||
47 | * Create a new Role model instance. |
||
48 | * |
||
49 | * @param array $attributes |
||
50 | */ |
||
51 | public function __construct(array $attributes = []) |
||
56 | |||
57 | /** |
||
58 | * Get all permissions attached to the role. |
||
59 | * |
||
60 | * @return BelongsToMany |
||
61 | */ |
||
62 | public function permissions() |
||
67 | |||
68 | /** |
||
69 | * Get all users that are attached to the role. |
||
70 | * |
||
71 | * @return BelongsToMany |
||
72 | */ |
||
73 | public function users() |
||
78 | |||
79 | /** |
||
80 | * Update the model in the database. |
||
81 | * |
||
82 | * @param array $attributes |
||
83 | * @param array $options |
||
84 | * @return bool|int |
||
85 | */ |
||
86 | public function update(array $attributes = [], array $options = []) |
||
96 | |||
97 | /** |
||
98 | * Add user to role. |
||
99 | * |
||
100 | * If user doesn't have same client id or role is locked, |
||
101 | * the action will be prevented. |
||
102 | * |
||
103 | * @param int $userid |
||
104 | */ |
||
105 | public function addUser($userid) |
||
117 | |||
118 | /** |
||
119 | * Remove user from role. |
||
120 | * |
||
121 | * If user doesn't have same client id or role is locked, |
||
122 | * the action will be prevented. |
||
123 | * |
||
124 | * @param int $userid |
||
125 | */ |
||
126 | public function removeUser($userid) |
||
137 | |||
138 | /** |
||
139 | * Add permission to role. |
||
140 | * |
||
141 | * If user doesn't have same client id or role is locked, |
||
142 | * the action will be prevented. |
||
143 | * |
||
144 | * @param string $permission |
||
145 | */ |
||
146 | public function addPermission($permission) |
||
160 | |||
161 | /** |
||
162 | * Remove permission from role. |
||
163 | * |
||
164 | * If user doesn't have same client id or role is locked, |
||
165 | * the action will be prevented. |
||
166 | * |
||
167 | * @param string $permission |
||
168 | */ |
||
169 | public function removePermission($permission) |
||
182 | |||
183 | /** |
||
184 | * Scope to require client ID is met. |
||
185 | * |
||
186 | * @param $query |
||
187 | * @return mixed |
||
188 | */ |
||
189 | public function scopeClient($query) |
||
196 | |||
197 | /** |
||
198 | * Scope to ensure selected roles are not locked. |
||
199 | * |
||
200 | * @param $query |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function scopeNotLocked($query) |
||
207 | } |