1 | <?php |
||
8 | trait TeamworkTeamTrait |
||
9 | { |
||
10 | /** |
||
11 | * One-to-Many relation with the invite model. |
||
12 | * @return mixed |
||
13 | */ |
||
14 | public function invites() |
||
18 | |||
19 | /** |
||
20 | * Many-to-Many relations with the user model. |
||
21 | * |
||
22 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
23 | */ |
||
24 | public function users() |
||
28 | |||
29 | /** |
||
30 | * Has-One relation with the user model. |
||
31 | * This indicates the owner of the team. |
||
32 | * |
||
33 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
34 | */ |
||
35 | public function owner() |
||
42 | |||
43 | /** |
||
44 | * Helper function to determine if a user is part |
||
45 | * of this team. |
||
46 | * |
||
47 | * @param Model $user |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function hasUser(Model $user) |
||
54 | } |
||
55 |
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.