1 | <?php |
||
16 | trait HasRole |
||
17 | { |
||
18 | private $roleClass; |
||
19 | |||
20 | /** |
||
21 | * Check if user have access using any of the acl. |
||
22 | * |
||
23 | * @param array $acl |
||
24 | * @return boolean |
||
25 | */ |
||
26 | public function canAccess(array $acl): bool |
||
30 | |||
31 | /** |
||
32 | * Check if user has at least one of the given permissions |
||
33 | * |
||
34 | * @param array $permissions |
||
35 | * @return bool |
||
36 | */ |
||
37 | public function canAtLeast(array $permissions): bool |
||
57 | |||
58 | /** |
||
59 | * Find a role by slug. |
||
60 | * |
||
61 | * @param string $slug |
||
62 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null |
||
63 | */ |
||
64 | protected function findRoleBySlug(string $slug): ?Role |
||
68 | |||
69 | /** |
||
70 | * Get Role class. |
||
71 | * |
||
72 | * @return Role |
||
73 | */ |
||
74 | public function getRoleClass(): Role |
||
82 | |||
83 | /** |
||
84 | * Check if user has the given role. |
||
85 | * |
||
86 | * @param string|array $role |
||
87 | * @return bool |
||
88 | */ |
||
89 | public function hasRole($role): bool |
||
102 | |||
103 | /** |
||
104 | * Get all user roles. |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | public function getRoleSlugs(): array |
||
112 | |||
113 | /** |
||
114 | * Attach a role to user using slug. |
||
115 | * |
||
116 | * @param string $slug |
||
117 | */ |
||
118 | public function attachRoleBySlug(string $slug) |
||
122 | |||
123 | /** |
||
124 | * Attach a role to user. |
||
125 | * |
||
126 | * @param mixed $role |
||
127 | */ |
||
128 | public function attachRole($role) |
||
132 | |||
133 | /** |
||
134 | * Model can have many roles. |
||
135 | * |
||
136 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
137 | */ |
||
138 | public function roles(): BelongsToMany |
||
142 | |||
143 | /** |
||
144 | * Query scope for user having the given roles. |
||
145 | * |
||
146 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
147 | * @param array $roles |
||
148 | * @return \Illuminate\Database\Eloquent\Builder |
||
149 | */ |
||
150 | public function scopeHavingRoles(Builder $query, array $roles): Builder |
||
159 | |||
160 | /** |
||
161 | * Query scope for user having the given roles by slugs. |
||
162 | * |
||
163 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
164 | * @param array $slugs |
||
165 | * @return \Illuminate\Database\Eloquent\Builder |
||
166 | */ |
||
167 | public function scopeHavingRolesBySlugs(Builder $query, array $slugs): Builder |
||
173 | |||
174 | /** |
||
175 | * Revokes the given role from the user using slug. |
||
176 | * |
||
177 | * @param string $slug |
||
178 | * @return int |
||
179 | */ |
||
180 | public function revokeRoleBySlug(string $slug): int |
||
186 | |||
187 | /** |
||
188 | * Revokes the given role from the user. |
||
189 | * |
||
190 | * @param mixed $role |
||
191 | * @return int |
||
192 | */ |
||
193 | public function revokeRole($role = ""): int |
||
197 | |||
198 | /** |
||
199 | * Syncs the given role(s) with the user. |
||
200 | * |
||
201 | * @param array $roles |
||
202 | * @return array |
||
203 | */ |
||
204 | public function syncRoles(array $roles): array |
||
208 | |||
209 | /** |
||
210 | * Revokes all roles from the user. |
||
211 | * |
||
212 | * @return int |
||
213 | */ |
||
214 | public function revokeAllRoles(): int |
||
218 | |||
219 | /** |
||
220 | * Get all user role permissions. |
||
221 | * |
||
222 | * @return array |
||
223 | */ |
||
224 | public function getPermissions(): array |
||
234 | |||
235 | /** |
||
236 | * Magic __call method to handle dynamic methods. |
||
237 | * |
||
238 | * @param string $method |
||
239 | * @param array $arguments |
||
240 | * @return mixed |
||
241 | */ |
||
242 | public function __call($method, $arguments = []) |
||
260 | |||
261 | /** |
||
262 | * Checks if the user has the given role. |
||
263 | * |
||
264 | * @param string $slug |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function isRole(string $slug): bool |
||
279 | |||
280 | /** |
||
281 | * Check if the given entity/model is owned by the user. |
||
282 | * |
||
283 | * @param \Illuminate\Database\Eloquent\Model $entity |
||
284 | * @param string $relation |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function owns(Model $entity, $relation = 'user_id'): bool |
||
291 | } |
||
292 |
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: