1 | <?php |
||
7 | trait UserOnly |
||
8 | { |
||
9 | /** |
||
10 | * USER |
||
11 | * A User can have permissions explicitly assigned to it |
||
12 | * |
||
13 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
14 | */ |
||
15 | 15 | public function permissions() |
|
19 | |||
20 | /** |
||
21 | * USER |
||
22 | * Negate a permission from a User |
||
23 | * |
||
24 | * @param $permission |
||
25 | */ |
||
26 | 1 | public function negatePermission($permission) |
|
30 | |||
31 | /** |
||
32 | * Negate an array of permissions from a User |
||
33 | * |
||
34 | * @param $permissions |
||
35 | */ |
||
36 | 1 | public function negatePermissions(array $permissions) |
|
40 | |||
41 | /** |
||
42 | * First try the cache to return the collection, |
||
43 | * then fetch it from the database. |
||
44 | * |
||
45 | * See @cacheGetNegatedPermissions() |
||
46 | * |
||
47 | * @return \Illuminate\Support\Collection |
||
48 | */ |
||
49 | 3 | public function getNegatedPermissions() |
|
59 | |||
60 | /** |
||
61 | * Return a collection of permissions that |
||
62 | * are negated for a User |
||
63 | * |
||
64 | * @return \Illuminate\Support\Collection |
||
65 | */ |
||
66 | 3 | protected function cacheGetNegatedPermissions() |
|
70 | } |
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.