1 | <?php |
||
14 | trait CanFollow |
||
15 | { |
||
16 | /** |
||
17 | * Follow a followable entity. |
||
18 | * |
||
19 | * @param int|array|\Illuminate\Database\Eloquent\Model $followable |
||
20 | * @param string $className |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | 7 | public function follow($followable, $className = __CLASS__) |
|
28 | |||
29 | /** |
||
30 | * Unfollow a followable entity. |
||
31 | * |
||
32 | * @param int|array|\Illuminate\Database\Eloquent\Model $followable |
||
33 | * @param string $className |
||
34 | * |
||
35 | * @return bool|null |
||
36 | */ |
||
37 | public function unfollow($followable, $className = __CLASS__) |
||
41 | |||
42 | /** |
||
43 | * Check if entity is following given entity. |
||
44 | * |
||
45 | * @param int|\Illuminate\Database\Eloquent\Model $followable |
||
46 | * @param string $className |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function isFollowing($followable, $className = __CLASS__) |
||
54 | |||
55 | /** |
||
56 | * Toggle follow a followable or followables. |
||
57 | * |
||
58 | * @param int|array|\Illuminate\Database\Eloquent\Model $followable |
||
59 | * @param string $className |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | 1 | public function toggleFollow($followable, $className = __CLASS__) |
|
67 | |||
68 | /** |
||
69 | * Return entity following. |
||
70 | * |
||
71 | * @param string $className |
||
72 | * |
||
73 | * @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
||
74 | */ |
||
75 | 8 | public function following($className = __CLASS__) |
|
79 | } |
||
80 |
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.