1 | <?php |
||
12 | trait Voteable |
||
13 | { |
||
14 | /** |
||
15 | * This model has many votes. |
||
16 | * |
||
17 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
18 | */ |
||
19 | public function votes() |
||
23 | |||
24 | public function votesCount() |
||
28 | |||
29 | /** |
||
30 | * @return mixed |
||
31 | */ |
||
32 | public function upVotesCount() |
||
36 | |||
37 | /** |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function downVotesCount() |
||
44 | |||
45 | public function isVoted() |
||
49 | |||
50 | /** |
||
51 | * @return bool |
||
52 | */ |
||
53 | public function isUpVoted() |
||
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | public function isDownVoted() |
||
65 | |||
66 | public function isVotedByUser(int $user_id) |
||
70 | |||
71 | /** |
||
72 | * @param int $user_id |
||
73 | * |
||
74 | * @return bool |
||
75 | */ |
||
76 | public function isUpVotedByUser(int $user_id) |
||
80 | |||
81 | /** |
||
82 | * @param int $user_id |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function isDownVotedByUser(int $user_id) |
||
90 | |||
91 | /** |
||
92 | * @param Builder $query |
||
93 | * @param string $direction |
||
94 | * @param string $type |
||
95 | * |
||
96 | * @return Builder |
||
97 | */ |
||
98 | public function scopeOrderByVotes(Builder $query, string $direction = 'asc') |
||
110 | |||
111 | /** |
||
112 | * @param Builder $query |
||
113 | * @param string $direction |
||
114 | * @param string $type |
||
115 | * |
||
116 | * @return Builder |
||
117 | */ |
||
118 | public function scopeOrderByUpVotes(Builder $query, string $direction = 'asc', string $type = '>=') |
||
131 | |||
132 | /** |
||
133 | * @param Builder $query |
||
134 | * @param string $direction |
||
135 | * |
||
136 | * @return Builder |
||
137 | */ |
||
138 | public function scopeOrderByDownVotes(Builder $query, string $direction = 'asc') |
||
142 | |||
143 | /** |
||
144 | * @param int $vote_id |
||
145 | * |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function cancelVote(int $vote_id) |
||
152 | |||
153 | /** |
||
154 | * @return mixed |
||
155 | */ |
||
156 | public function resetVotes() |
||
160 | |||
161 | /** |
||
162 | * @param int $user_id |
||
163 | * |
||
164 | * @return mixed |
||
165 | */ |
||
166 | public function cancelVotesForUser(int $user_id) |
||
170 | |||
171 | /** |
||
172 | * @param int $user_id |
||
173 | * @param int $amount |
||
174 | * |
||
175 | * @return int |
||
176 | */ |
||
177 | public function updateVotesForUser(int $user_id, int $amount) |
||
181 | |||
182 | /** |
||
183 | * @param int $vote_id |
||
184 | * @param int $amount |
||
185 | * |
||
186 | * @return int |
||
187 | */ |
||
188 | public function updateVote(int $vote_id, int $amount) |
||
192 | |||
193 | /** |
||
194 | * @return VoteBuilder |
||
195 | * |
||
196 | * @throws \Throwable |
||
197 | */ |
||
198 | public function getVoteBuilder() |
||
203 | |||
204 | /** |
||
205 | * @return VoteQueryBuilder |
||
206 | */ |
||
207 | public function getVoteQueryBuilder() |
||
211 | |||
212 | public function voters() |
||
216 | |||
217 | public function countVotesByDate($from = null, $to = null) |
||
231 | } |
||
232 |
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.