1 | <?php |
||
13 | trait HasRole |
||
14 | { |
||
15 | private $roleClass; |
||
16 | |||
17 | /** |
||
18 | * Check if user have access using any of the acl. |
||
19 | * |
||
20 | * @param array $acl |
||
21 | * @return boolean |
||
22 | */ |
||
23 | public function canAccess(array $acl) |
||
27 | |||
28 | /** |
||
29 | * Check if user has at least one of the given permissions |
||
30 | * |
||
31 | * @param array $permissions |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function canAtLeast(array $permissions) |
||
54 | |||
55 | /** |
||
56 | * Get Role class. |
||
57 | * |
||
58 | * @return Role |
||
59 | */ |
||
60 | public function getRoleClass() |
||
68 | |||
69 | /** |
||
70 | * Check if user has the given role. |
||
71 | * |
||
72 | * @param string|array $role |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function hasRole($role) |
||
92 | |||
93 | /** |
||
94 | * Get all user roles. |
||
95 | * |
||
96 | * @return array|null |
||
97 | */ |
||
98 | public function getRoleSlugs() |
||
106 | |||
107 | /** |
||
108 | * Attach a role to user using slug. |
||
109 | * |
||
110 | * @param $slug |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function attachRoleBySlug($slug) |
||
119 | |||
120 | /** |
||
121 | * Attach a role to user |
||
122 | * |
||
123 | * @param Role $role |
||
124 | * @return boolean |
||
125 | */ |
||
126 | public function attachRole(Role $role) |
||
130 | |||
131 | /** |
||
132 | * Assigns the given role to the user. |
||
133 | * |
||
134 | * @param int $roleId |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function assignRole($roleId = null) |
||
147 | |||
148 | /** |
||
149 | * Model can have many roles. |
||
150 | * |
||
151 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
152 | */ |
||
153 | public function roles() |
||
157 | |||
158 | /** |
||
159 | * Query scope for user having the given roles. |
||
160 | * |
||
161 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
162 | * @param array $roles |
||
163 | * @return mixed |
||
164 | */ |
||
165 | public function scopeHavingRoles($query, array $roles) |
||
174 | |||
175 | /** |
||
176 | * Query scope for user having the given roles by slugs. |
||
177 | * |
||
178 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
179 | * @param array $roles |
||
180 | * @return mixed |
||
181 | */ |
||
182 | public function scopeHavingRolesBySlugs($query, array $slugs) |
||
188 | |||
189 | /** |
||
190 | * Revokes the given role from the user using slug. |
||
191 | * |
||
192 | * @param string $slug |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function revokeRoleBySlug($slug) |
||
201 | |||
202 | /** |
||
203 | * Revokes the given role from the user. |
||
204 | * |
||
205 | * @param mixed $role |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function revokeRole($role = "") |
||
212 | |||
213 | /** |
||
214 | * Syncs the given role(s) with the user. |
||
215 | * |
||
216 | * @param array $roles |
||
217 | * @return bool |
||
218 | */ |
||
219 | public function syncRoles(array $roles) |
||
223 | |||
224 | /** |
||
225 | * Revokes all roles from the user. |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function revokeAllRoles() |
||
233 | |||
234 | /** |
||
235 | * Get all user role permissions. |
||
236 | * |
||
237 | * @return array|null |
||
238 | */ |
||
239 | public function getPermissions() |
||
249 | |||
250 | /** |
||
251 | * Magic __call method to handle dynamic methods. |
||
252 | * |
||
253 | * @param string $method |
||
254 | * @param array $arguments |
||
255 | * @return mixed |
||
256 | */ |
||
257 | public function __call($method, $arguments = []) |
||
275 | |||
276 | /** |
||
277 | * Checks if the user has the given role. |
||
278 | * |
||
279 | * @param string $slug |
||
280 | * @return bool |
||
281 | */ |
||
282 | public function isRole($slug) |
||
294 | |||
295 | /** |
||
296 | * Check if the given entity/model is owned by the user. |
||
297 | * |
||
298 | * @param \Illuminate\Database\Eloquent\Model $entity |
||
299 | * @param string $relation |
||
300 | * @return bool |
||
301 | */ |
||
302 | public function owns($entity, $relation = 'user_id') |
||
306 | } |
||
307 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: