1 | <?php |
||
11 | trait HasRole |
||
12 | { |
||
13 | /** |
||
14 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
15 | */ |
||
16 | 94 | public function roles(): BelongsToMany |
|
17 | { |
||
18 | 94 | return $this->belongsToMany(config('acl.models.role'), config('acl.table_names.users_roles')); |
|
|
|||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @throws \Exception |
||
23 | * |
||
24 | * @return bool |
||
25 | */ |
||
26 | 2 | public function delete() |
|
32 | |||
33 | /** |
||
34 | * @return bool |
||
35 | */ |
||
36 | 2 | public function getDeleteableAttribute(): bool |
|
43 | |||
44 | /** |
||
45 | * @return Collection |
||
46 | */ |
||
47 | 56 | public function getRoles() |
|
51 | |||
52 | /** |
||
53 | * @return array |
||
54 | */ |
||
55 | 46 | public function getRoleIds(): array |
|
65 | |||
66 | /** |
||
67 | * Returns an array of merged permissions for each group the user is in. |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 34 | public function getMergedPermissions(): array |
|
81 | |||
82 | /** |
||
83 | * @return array |
||
84 | */ |
||
85 | 34 | public function getPermissions(): array |
|
89 | |||
90 | /** |
||
91 | * @return bool |
||
92 | */ |
||
93 | 44 | public function isSuperUser(): bool |
|
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | 46 | public function isAdmin(): bool |
|
105 | |||
106 | /** |
||
107 | * @return int Lowest value of the users groups access levels |
||
108 | */ |
||
109 | 2 | public function getAccessLevels(): int |
|
120 | |||
121 | /** |
||
122 | * @param int $level |
||
123 | * @param int $parent |
||
124 | * @param int $current |
||
125 | * |
||
126 | * @return int |
||
127 | */ |
||
128 | 2 | protected function getLowestAccessLevel($level, $parent, $current): int |
|
132 | } |
||
133 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.