1 | <?php |
||
12 | trait UserHasTeams |
||
13 | { |
||
14 | /** |
||
15 | * Many-to-Many relations with the user model. |
||
16 | * |
||
17 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
18 | */ |
||
19 | public function teams() |
||
23 | |||
24 | /** |
||
25 | * has-one relation with the current selected team model. |
||
26 | * |
||
27 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
28 | */ |
||
29 | public function currentTeam() |
||
33 | |||
34 | /** |
||
35 | * @return mixed |
||
36 | */ |
||
37 | public function ownedTeams() |
||
41 | |||
42 | /** |
||
43 | * One-to-Many relation with the invite model. |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function invites() |
||
50 | |||
51 | /** |
||
52 | * Boot the user model |
||
53 | * Attach event listener to remove the many-to-many records when trying to delete |
||
54 | * Will NOT delete any records if the user model uses soft deletes. |
||
55 | * |
||
56 | * @return void|bool |
||
57 | */ |
||
58 | public static function bootUserHasTeams() |
||
68 | |||
69 | /** |
||
70 | * Returns if the user owns a team. |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function isOwner() |
||
78 | |||
79 | /** |
||
80 | * Wrapper method for "isOwner". |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function isTeamOwner() |
||
88 | |||
89 | /** |
||
90 | * @param $team |
||
91 | * @return mixed |
||
92 | */ |
||
93 | protected function retrieveTeamId($team) |
||
104 | |||
105 | /** |
||
106 | * Returns if the user owns the given team. |
||
107 | * |
||
108 | * @param mixed $team |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function isOwnerOfTeam($team) |
||
120 | |||
121 | /** |
||
122 | * Alias to eloquent many-to-many relation's attach() method. |
||
123 | * |
||
124 | * @param mixed $team |
||
125 | * @param array $pivotData |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function attachTeam($team, $pivotData = []) |
||
159 | |||
160 | /** |
||
161 | * Alias to eloquent many-to-many relation's detach() method. |
||
162 | * |
||
163 | * @param mixed $team |
||
164 | * @return $this |
||
165 | */ |
||
166 | public function detachTeam($team) |
||
192 | |||
193 | /** |
||
194 | * Attach multiple teams to a user. |
||
195 | * |
||
196 | * @param mixed $teams |
||
197 | * @return $this |
||
198 | */ |
||
199 | public function attachTeams($teams) |
||
207 | |||
208 | /** |
||
209 | * Detach multiple teams from a user. |
||
210 | * |
||
211 | * @param mixed $teams |
||
212 | * @return $this |
||
213 | */ |
||
214 | public function detachTeams($teams) |
||
222 | |||
223 | /** |
||
224 | * Switch the current team of the user. |
||
225 | * |
||
226 | * @param object|array|int $team |
||
227 | * @return $this |
||
228 | * @throws ModelNotFoundException |
||
229 | * @throws UserNotInTeamException |
||
230 | */ |
||
231 | public function switchTeam($team) |
||
257 | } |
||
258 |
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.