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 | public function isVoted() |
||
50 | |||
51 | /** |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function isUpVoted() |
||
58 | |||
59 | /** |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function isDownVoted() |
||
66 | |||
67 | public function isVotedByUser(int $user_id) |
||
71 | |||
72 | /** |
||
73 | * @param int $user_id |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function isUpVotedByUser(int $user_id) |
||
81 | |||
82 | /** |
||
83 | * @param int $user_id |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function isDownVotedByUser(int $user_id) |
||
91 | |||
92 | /** |
||
93 | * @param Builder $query |
||
94 | * @param string $direction |
||
95 | * @param string $type |
||
96 | * |
||
97 | * @return Builder |
||
98 | */ |
||
99 | public function scopeOrderByVotes(Builder $query, string $direction = 'asc') |
||
111 | |||
112 | /** |
||
113 | * @param Builder $query |
||
114 | * @param string $direction |
||
115 | * @param string $type |
||
116 | * |
||
117 | * @return Builder |
||
118 | */ |
||
119 | public function scopeOrderByUpVotes(Builder $query, string $direction = 'asc', string $type = '>=') |
||
132 | |||
133 | /** |
||
134 | * @param Builder $query |
||
135 | * @param string $direction |
||
136 | * |
||
137 | * @return Builder |
||
138 | */ |
||
139 | public function scopeOrderByDownVotes(Builder $query, string $direction = 'asc') |
||
143 | |||
144 | /** |
||
145 | * @param int $vote_id |
||
146 | * |
||
147 | * @return mixed |
||
148 | */ |
||
149 | public function cancelVote(int $vote_id) |
||
153 | |||
154 | /** |
||
155 | * @return mixed |
||
156 | */ |
||
157 | public function resetVotes() |
||
161 | |||
162 | /** |
||
163 | * @param int $user_id |
||
164 | * |
||
165 | * @return mixed |
||
166 | */ |
||
167 | public function cancelVotesForUser(int $user_id) |
||
171 | |||
172 | /** |
||
173 | * @param int $user_id |
||
174 | * @param int $amount |
||
175 | * |
||
176 | * @return int |
||
177 | */ |
||
178 | public function updateVotesForUser(int $user_id, int $amount) |
||
182 | |||
183 | /** |
||
184 | * @param int $vote_id |
||
185 | * @param int $amount |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | public function updateVote(int $vote_id, int $amount) |
||
193 | |||
194 | /** |
||
195 | * @return VoteBuilder |
||
196 | * |
||
197 | * @throws \Throwable |
||
198 | */ |
||
199 | public function getVoteBuilder() |
||
204 | |||
205 | /** |
||
206 | * @return VoteQueryBuilder |
||
207 | * |
||
208 | * @throws \Throwable |
||
209 | */ |
||
210 | public function getVoteQueryBuilder() |
||
214 | |||
215 | public function voters() |
||
219 | |||
220 | public function countVotesByDate($from = null, $to = null) |
||
234 | } |
||
235 |
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.