1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
28 | class Role extends Model implements RoleContract |
||
29 | { |
||
30 | /* ------------------------------------------------------------------------------------------------ |
||
31 | | Traits |
||
32 | | ------------------------------------------------------------------------------------------------ |
||
33 | */ |
||
34 | use RoleRelationships, Activatable; |
||
35 | |||
36 | /* ------------------------------------------------------------------------------------------------ |
||
37 | | Properties |
||
38 | | ------------------------------------------------------------------------------------------------ |
||
39 | */ |
||
40 | /** |
||
41 | * The attributes that are mass assignable. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $fillable = ['name', 'slug', 'description']; |
||
46 | |||
47 | /** |
||
48 | * The attributes that should be casted to native types. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $casts = [ |
||
53 | 'is_active' => 'boolean', |
||
54 | 'is_locked' => 'boolean', |
||
55 | ]; |
||
56 | |||
57 | /* ------------------------------------------------------------------------------------------------ |
||
58 | | Constructor |
||
59 | | ------------------------------------------------------------------------------------------------ |
||
60 | */ |
||
61 | /** |
||
62 | * Create a new Eloquent model instance. |
||
63 | * |
||
64 | * @param array $attributes |
||
65 | */ |
||
66 | 528 | public function __construct(array $attributes = []) |
|
67 | { |
||
68 | 528 | $this->setTable(config('laravel-auth.roles.table', 'roles')); |
|
69 | |||
70 | 528 | parent::__construct($attributes); |
|
71 | 528 | } |
|
72 | |||
73 | /* ------------------------------------------------------------------------------------------------ |
||
74 | | Getters & Setters |
||
75 | | ------------------------------------------------------------------------------------------------ |
||
76 | */ |
||
77 | /** |
||
78 | * Set the name attribute. |
||
79 | * |
||
80 | * @param string $name |
||
81 | */ |
||
82 | 224 | public function setNameAttribute($name) |
|
87 | |||
88 | /** |
||
89 | * Set the slug attribute. |
||
90 | * |
||
91 | * @param string $slug |
||
92 | */ |
||
93 | 224 | public function setSlugAttribute($slug) |
|
97 | |||
98 | /* ------------------------------------------------------------------------------------------------ |
||
99 | | CRUD Functions |
||
100 | | ------------------------------------------------------------------------------------------------ |
||
101 | */ |
||
102 | /** |
||
103 | * Attach a permission to a role. |
||
104 | * |
||
105 | * @param \Arcanesoft\Contracts\Auth\Models\User|int $user |
||
106 | * @param bool $reload |
||
107 | */ |
||
108 | 24 | public function attachUser($user, $reload = true) |
|
115 | |||
116 | /** |
||
117 | * Detach a user from a role. |
||
118 | * |
||
119 | * @param \Arcanesoft\Contracts\Auth\Models\User|int $user |
||
120 | * @param bool $reload |
||
121 | * |
||
122 | * @return int |
||
123 | */ |
||
124 | 8 | public function detachUser($user, $reload = true) |
|
134 | |||
135 | /** |
||
136 | * Detach all users from a role. |
||
137 | * |
||
138 | * @param bool $reload |
||
139 | * |
||
140 | * @return int |
||
141 | */ |
||
142 | public function detachAllUsers($reload = true) |
||
149 | |||
150 | /** |
||
151 | * Check if role has the given user (User Model or Id). |
||
152 | * |
||
153 | * @param \Arcanesoft\Contracts\Auth\Models\User|int $id |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function hasUser($id) |
||
164 | 24 | ||
165 | /** |
||
166 | * Attach a permission to a role. |
||
167 | * |
||
168 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $permission |
||
169 | * @param bool $reload |
||
170 | */ |
||
171 | public function attachPermission($permission, $reload = true) |
||
178 | 54 | ||
179 | 72 | /** |
|
180 | * Detach a permission from a role. |
||
181 | * |
||
182 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $permission |
||
183 | * @param bool $reload |
||
184 | * |
||
185 | * @return int |
||
186 | */ |
||
187 | public function detachPermission($permission, $reload = true) |
||
197 | |||
198 | 8 | /** |
|
199 | * Detach all permissions from a role. |
||
200 | * |
||
201 | * @param bool $reload |
||
202 | * |
||
203 | * @return int |
||
204 | */ |
||
205 | public function detachAllPermissions($reload = true) |
||
212 | |||
213 | 8 | /** |
|
214 | * Check if role has the given permission (Permission Model or Id). |
||
215 | * |
||
216 | * @param mixed $id |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function hasPermission($id) |
||
227 | 54 | ||
228 | /* ------------------------------------------------------------------------------------------------ |
||
229 | 72 | | Check Functions |
|
230 | | ------------------------------------------------------------------------------------------------ |
||
231 | */ |
||
232 | /** |
||
233 | * Check if role is associated with a permission by slug. |
||
234 | * |
||
235 | * @param string $slug |
||
236 | * |
||
237 | * @return bool |
||
238 | */ |
||
239 | public function can($slug) |
||
247 | 24 | ||
248 | /** |
||
249 | 24 | * Check if a role is associated with any of given permissions. |
|
250 | * |
||
251 | * @param array $permissions |
||
252 | * @param array &$failedPermissions |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function canAny(array $permissions, array &$failedPermissions = []) |
||
265 | 12 | ||
266 | 12 | /** |
|
267 | * Check if role is associated with all given permissions. |
||
268 | 16 | * |
|
269 | * @param array $permissions |
||
270 | * @param array &$failedPermissions |
||
271 | * |
||
272 | * @return bool |
||
273 | */ |
||
274 | public function canAll(array $permissions, array &$failedPermissions = []) |
||
280 | |||
281 | 8 | /** |
|
282 | * Check if the role is locked. |
||
283 | 8 | * |
|
284 | * @return bool |
||
285 | */ |
||
286 | public function isLocked() |
||
290 | |||
291 | 16 | /** |
|
292 | * Check if slug is the same as the given value. |
||
293 | 16 | * |
|
294 | * @param string $value |
||
295 | * |
||
296 | * @return bool |
||
297 | */ |
||
298 | public function checkSlug($value) |
||
302 | |||
303 | /* ------------------------------------------------------------------------------------------------ |
||
304 | | Other Functions |
||
305 | | ------------------------------------------------------------------------------------------------ |
||
306 | */ |
||
307 | 24 | /** |
|
308 | * Load the users. |
||
309 | 24 | * |
|
310 | * @param bool $load |
||
311 | * |
||
312 | * @return self |
||
313 | */ |
||
314 | protected function loadUsers($load = true) |
||
318 | |||
319 | 72 | /** |
|
320 | * Load the permissions. |
||
321 | 72 | * |
|
322 | * @param bool $load |
||
323 | * |
||
324 | * @return self |
||
325 | */ |
||
326 | protected function loadPermissions($load = true) |
||
330 | |||
331 | /** |
||
332 | * Slugify the value. |
||
333 | * |
||
334 | * @param string $value |
||
335 | * |
||
336 | * @return string |
||
337 | */ |
||
338 | protected function slugify($value) |
||
342 | } |
||
343 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.