1 | <?php |
||
8 | trait HasRole |
||
9 | { |
||
10 | private $roleClass; |
||
11 | |||
12 | /** |
||
13 | * Check if user have access using any of the acl. |
||
14 | * |
||
15 | * @param array $acl |
||
16 | * @return boolean |
||
17 | */ |
||
18 | public function canAccess(array $acl) |
||
22 | |||
23 | /** |
||
24 | * Check if user has at least one of the given permissions |
||
25 | * |
||
26 | * @param array $permissions |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function canAtLeast(array $permissions) |
||
49 | |||
50 | /** |
||
51 | * Get Role class. |
||
52 | * |
||
53 | * @return Role |
||
54 | */ |
||
55 | public function getRoleClass() |
||
63 | |||
64 | /** |
||
65 | * Check if user has the given role. |
||
66 | * |
||
67 | * @param string|array $role |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function hasRole($role) |
||
87 | |||
88 | /** |
||
89 | * Get all user roles. |
||
90 | * |
||
91 | * @return array|null |
||
92 | */ |
||
93 | public function getRoleSlugs() |
||
101 | |||
102 | /** |
||
103 | * Attach a role to user using slug. |
||
104 | * |
||
105 | * @param $slug |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function attachRoleBySlug($slug) |
||
114 | |||
115 | /** |
||
116 | * Attach a role to user |
||
117 | * |
||
118 | * @param Role $role |
||
119 | * @return boolean |
||
120 | */ |
||
121 | public function attachRole(Role $role) |
||
125 | |||
126 | /** |
||
127 | * Assigns the given role to the user. |
||
128 | * |
||
129 | * @param int $roleId |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function assignRole($roleId = null) |
||
142 | |||
143 | /** |
||
144 | * Model can have many roles. |
||
145 | * |
||
146 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
147 | */ |
||
148 | public function roles() |
||
152 | |||
153 | /** |
||
154 | * Query scope for user having the given roles. |
||
155 | * |
||
156 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
157 | * @param array $roles |
||
158 | * @return mixed |
||
159 | */ |
||
160 | public function scopeHavingRoles($query, array $roles) |
||
169 | |||
170 | /** |
||
171 | * Revokes the given role from the user using slug. |
||
172 | * |
||
173 | * @param string $slug |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function revokeRoleBySlug($slug) |
||
182 | |||
183 | /** |
||
184 | * Revokes the given role from the user. |
||
185 | * |
||
186 | * @param mixed $role |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function revokeRole($role = "") |
||
193 | |||
194 | /** |
||
195 | * Syncs the given role(s) with the user. |
||
196 | * |
||
197 | * @param array $roles |
||
198 | * @return bool |
||
199 | */ |
||
200 | public function syncRoles(array $roles) |
||
204 | |||
205 | /** |
||
206 | * Revokes all roles from the user. |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function revokeAllRoles() |
||
214 | |||
215 | /** |
||
216 | * Get all user role permissions. |
||
217 | * |
||
218 | * @return array|null |
||
219 | */ |
||
220 | public function getPermissions() |
||
230 | |||
231 | /** |
||
232 | * Magic __call method to handle dynamic methods. |
||
233 | * |
||
234 | * @param string $method |
||
235 | * @param array $arguments |
||
236 | * @return mixed |
||
237 | */ |
||
238 | public function __call($method, $arguments = []) |
||
256 | |||
257 | /** |
||
258 | * Checks if the user has the given role. |
||
259 | * |
||
260 | * @param string $slug |
||
261 | * @return bool |
||
262 | */ |
||
263 | public function isRole($slug) |
||
275 | |||
276 | /** |
||
277 | * Check if the given entity/model is owned by the user. |
||
278 | * |
||
279 | * @param \Illuminate\Database\Eloquent\Model $entity |
||
280 | * @param string $relation |
||
281 | * @return bool |
||
282 | */ |
||
283 | public function owns($entity, $relation = 'user_id') |
||
287 | } |
||
288 |
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: