1 | <?php |
||
21 | trait Messagable |
||
22 | { |
||
23 | /* ----------------------------------------------------------------- |
||
24 | | Relationships |
||
25 | | ----------------------------------------------------------------- |
||
26 | */ |
||
27 | |||
28 | /** |
||
29 | * Thread relationship. |
||
30 | * |
||
31 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
32 | */ |
||
33 | 12 | public function discussions() |
|
41 | |||
42 | /** |
||
43 | * Participations relationship. |
||
44 | * |
||
45 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
46 | */ |
||
47 | 6 | public function participations() |
|
54 | |||
55 | /** |
||
56 | * Message relationship. |
||
57 | * |
||
58 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
59 | */ |
||
60 | 6 | public function messages() |
|
67 | |||
68 | /* ----------------------------------------------------------------- |
||
69 | | Main Methods |
||
70 | | ----------------------------------------------------------------- |
||
71 | */ |
||
72 | |||
73 | /** |
||
74 | * Returns the new messages count for user. |
||
75 | * |
||
76 | * @return int |
||
77 | */ |
||
78 | 6 | public function newMessagesCount() |
|
82 | |||
83 | /** |
||
84 | * Returns all discussions IDs with new messages. |
||
85 | * |
||
86 | * @return \Illuminate\Database\Eloquent\Collection |
||
87 | */ |
||
88 | 6 | public function discussionsWithNewMessages() |
|
100 | } |
||
101 |
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.