1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
29 | class PermissionsGroup extends AbstractModel implements PermissionsGroupContract |
||
30 | { |
||
31 | /* ----------------------------------------------------------------- |
||
32 | | Properties |
||
33 | | ----------------------------------------------------------------- |
||
34 | */ |
||
35 | |||
36 | /** |
||
37 | * The attributes that are mass assignable. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $fillable = ['name', 'slug', 'description']; |
||
42 | |||
43 | /** |
||
44 | * The event map for the model. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $dispatchesEvents = [ |
||
49 | 'creating' => CreatingPermissionsGroup::class, |
||
50 | 'created' => CreatedPermissionsGroup::class, |
||
51 | 'updating' => UpdatingPermissionsGroup::class, |
||
52 | 'updated' => UpdatedPermissionsGroup::class, |
||
53 | 'saving' => SavingPermissionsGroup::class, |
||
54 | 'saved' => SavedPermissionsGroup::class, |
||
55 | 'deleting' => DeletingPermissionsGroup::class, |
||
56 | 'deleted' => DeletedPermissionsGroup::class, |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * The attributes that should be cast to native types. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $casts = [ |
||
65 | 'id' => 'integer', |
||
66 | ]; |
||
67 | |||
68 | /* ----------------------------------------------------------------- |
||
69 | | Constructor |
||
70 | | ----------------------------------------------------------------- |
||
71 | */ |
||
72 | |||
73 | /** |
||
74 | * Create a new Eloquent model instance. |
||
75 | * |
||
76 | * @param array $attributes |
||
77 | */ |
||
78 | 48 | public function __construct(array $attributes = []) |
|
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Relationships |
||
89 | | ----------------------------------------------------------------- |
||
90 | */ |
||
91 | |||
92 | /** |
||
93 | * Permissions Groups has many permissions. |
||
94 | * |
||
95 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
96 | */ |
||
97 | 39 | public function permissions() |
|
104 | |||
105 | /* ----------------------------------------------------------------- |
||
106 | | Getters & Setters |
||
107 | | ----------------------------------------------------------------- |
||
108 | */ |
||
109 | |||
110 | /** |
||
111 | * Set the name attribute. |
||
112 | * |
||
113 | * @param string $name |
||
114 | */ |
||
115 | 39 | public function setNameAttribute($name) |
|
120 | |||
121 | /** |
||
122 | * Set the slug attribute. |
||
123 | * |
||
124 | * @param string $slug |
||
125 | */ |
||
126 | 39 | public function setSlugAttribute($slug) |
|
130 | |||
131 | /* ----------------------------------------------------------------- |
||
132 | | Main Methods |
||
133 | | ----------------------------------------------------------------- |
||
134 | */ |
||
135 | |||
136 | /** |
||
137 | * Create and attach a permission. |
||
138 | * |
||
139 | * @param array $attributes |
||
140 | * @param bool $reload |
||
141 | */ |
||
142 | 6 | public function createPermission(array $attributes, $reload = true) |
|
148 | |||
149 | /** |
||
150 | * Attach the permission to a group. |
||
151 | * |
||
152 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
153 | * @param bool $reload |
||
154 | */ |
||
155 | 18 | public function attachPermission(&$permission, $reload = true) |
|
165 | |||
166 | /** |
||
167 | * Attach the permission by id to a group. |
||
168 | * |
||
169 | * @param int $id |
||
170 | * @param bool $reload |
||
171 | * |
||
172 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
173 | */ |
||
174 | 3 | public function attachPermissionById($id, $reload = true) |
|
183 | |||
184 | /** |
||
185 | * Attach a collection of permissions to the group. |
||
186 | * |
||
187 | * @param \Illuminate\Database\Eloquent\Collection|array $permissions |
||
188 | * @param bool $reload |
||
189 | * |
||
190 | * @return \Illuminate\Database\Eloquent\Collection|array |
||
191 | */ |
||
192 | 9 | public function attachPermissions($permissions, $reload = true) |
|
202 | |||
203 | /** |
||
204 | * Attach the permission from a group. |
||
205 | * |
||
206 | * @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
||
207 | * @param bool $reload |
||
208 | */ |
||
209 | 9 | public function detachPermission(&$permission, $reload = true) |
|
223 | |||
224 | /** |
||
225 | * Attach the permission by id to a group. |
||
226 | * |
||
227 | * @param int $id |
||
228 | * @param bool $reload |
||
229 | * |
||
230 | * @return \Arcanesoft\Contracts\Auth\Models\Permission |
||
231 | */ |
||
232 | 3 | public function detachPermissionById($id, $reload = true) |
|
239 | |||
240 | /** |
||
241 | * Detach multiple permissions by ids. |
||
242 | * |
||
243 | * @param array $ids |
||
244 | * @param bool $reload |
||
245 | * |
||
246 | * @return int |
||
247 | */ |
||
248 | 3 | public function detachPermissions(array $ids, $reload = true) |
|
258 | |||
259 | /** |
||
260 | * Detach all permissions from the group. |
||
261 | * |
||
262 | * @param bool $reload |
||
263 | * |
||
264 | * @return int |
||
265 | */ |
||
266 | 6 | public function detachAllPermissions($reload = true) |
|
276 | |||
277 | /* ----------------------------------------------------------------- |
||
278 | | Check Methods |
||
279 | | ----------------------------------------------------------------- |
||
280 | */ |
||
281 | |||
282 | /** |
||
283 | * Check if role has the given permission (Permission Model or Id). |
||
284 | * |
||
285 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | 24 | public function hasPermission($id) |
|
295 | |||
296 | /* ----------------------------------------------------------------- |
||
297 | | Other Methods |
||
298 | | ----------------------------------------------------------------- |
||
299 | */ |
||
300 | |||
301 | /** |
||
302 | * Get a permission from the group. |
||
303 | * |
||
304 | * @param \Arcanesoft\Contracts\Auth\Models\Permission|int $id |
||
305 | * |
||
306 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
307 | */ |
||
308 | 24 | private function getPermissionFromGroup($id) |
|
320 | |||
321 | /** |
||
322 | * Get a permission by id. |
||
323 | * |
||
324 | * @param int $id |
||
325 | * |
||
326 | * @return \Arcanesoft\Contracts\Auth\Models\Permission|null |
||
327 | */ |
||
328 | 6 | private function getPermissionById($id) |
|
332 | |||
333 | /** |
||
334 | * Load the permissions. |
||
335 | * |
||
336 | * @param bool $load |
||
337 | * |
||
338 | * @return self |
||
339 | */ |
||
340 | 33 | protected function loadPermissions($load = true) |
|
344 | } |
||
345 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: