1 | <?php |
||
13 | trait Voteable |
||
14 | { |
||
15 | /** |
||
16 | * This model has many votes. |
||
17 | * |
||
18 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
19 | */ |
||
20 | public function votes() |
||
24 | |||
25 | public function votesCount() |
||
29 | |||
30 | /** |
||
31 | * @return mixed |
||
32 | */ |
||
33 | public function upVotesCount() |
||
37 | |||
38 | /** |
||
39 | * @return mixed |
||
40 | */ |
||
41 | public function downVotesCount() |
||
45 | |||
46 | /** |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isUpVoted() |
||
53 | |||
54 | /** |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function isDownVoted() |
||
61 | |||
62 | public function isVotedByUser(int $user_id) |
||
66 | |||
67 | /** |
||
68 | * @param int $user_id |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function isUpVotedByUser(int $user_id) |
||
76 | |||
77 | /** |
||
78 | * @param int $user_id |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function isDownVotedByUser(int $user_id) |
||
86 | |||
87 | /** |
||
88 | * @param Builder $query |
||
89 | * @param string $direction |
||
90 | * @param string $type |
||
91 | * |
||
92 | * @return Builder |
||
93 | */ |
||
94 | public function scopeOrderByUpVotes(Builder $query, string $direction = 'asc', string $type = '>=') |
||
107 | |||
108 | /** |
||
109 | * @param Builder $query |
||
110 | * @param string $direction |
||
111 | * |
||
112 | * @return Builder |
||
113 | */ |
||
114 | public function scopeOrderByDownVotes(Builder $query, string $direction = 'asc') |
||
118 | |||
119 | /** |
||
120 | * @param int $vote_id |
||
121 | * |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function cancelVote(int $vote_id) |
||
128 | |||
129 | /** |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function resetVotes() |
||
136 | |||
137 | /** |
||
138 | * @param int $user_id |
||
139 | * |
||
140 | * @return mixed |
||
141 | */ |
||
142 | public function cancelVotesForUser(int $user_id) |
||
146 | |||
147 | /** |
||
148 | * @param int $user_id |
||
149 | * @param int $amount |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | public function updateVotesForUser(int $user_id, int $amount) |
||
157 | |||
158 | /** |
||
159 | * @param int $vote_id |
||
160 | * @param int $amount |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | public function updateVote(int $vote_id, int $amount) |
||
168 | |||
169 | /** |
||
170 | * @return VoteBuilder |
||
171 | * |
||
172 | * @throws \Throwable |
||
173 | */ |
||
174 | public function getVoteBuilder() |
||
179 | |||
180 | public function voters() |
||
184 | |||
185 | public function countVotesByDate($from, $to) |
||
191 | } |
||
192 |
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.