1 | <?php |
||
12 | trait IsBookingUser |
||
13 | { |
||
14 | /** |
||
15 | * The user may have many bookings. |
||
16 | * |
||
17 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
18 | */ |
||
19 | public function bookings(): HasMany |
||
23 | |||
24 | /** |
||
25 | * Get past bookings. |
||
26 | * |
||
27 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
28 | */ |
||
29 | public function pastBookings(): HasMany |
||
36 | |||
37 | /** |
||
38 | * Get future bookings. |
||
39 | * |
||
40 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
41 | */ |
||
42 | public function futureBookings(): HasMany |
||
49 | |||
50 | /** |
||
51 | * Get current bookings. |
||
52 | * |
||
53 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
54 | */ |
||
55 | public function currentBookings(): HasMany |
||
64 | |||
65 | /** |
||
66 | * Get cancelled bookings. |
||
67 | * |
||
68 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
69 | */ |
||
70 | public function cancelledBookings(): HasMany |
||
75 | |||
76 | /** |
||
77 | * Get bookings starts before the given date. |
||
78 | * |
||
79 | * @param string $date |
||
80 | * |
||
81 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
82 | */ |
||
83 | public function bookingsStartsBefore(string $date): HasMany |
||
90 | |||
91 | /** |
||
92 | * Get bookings starts after the given date. |
||
93 | * |
||
94 | * @param string $date |
||
95 | * |
||
96 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
97 | */ |
||
98 | public function bookingsStartsAfter(string $date): HasMany |
||
105 | |||
106 | /** |
||
107 | * Get bookings starts between the given dates. |
||
108 | * |
||
109 | * @param string $starts |
||
110 | * @param string $ends |
||
111 | * |
||
112 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
113 | */ |
||
114 | public function bookingsStartsBetween(string $starts, string $ends): HasMany |
||
122 | |||
123 | /** |
||
124 | * Get bookings ends before the given date. |
||
125 | * |
||
126 | * @param string $date |
||
127 | * |
||
128 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
129 | */ |
||
130 | public function bookingsEndsBefore(string $date): HasMany |
||
137 | |||
138 | /** |
||
139 | * Get bookings ends after the given date. |
||
140 | * |
||
141 | * @param string $date |
||
142 | * |
||
143 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
144 | */ |
||
145 | public function bookingsEndsAfter(string $date): HasMany |
||
152 | |||
153 | /** |
||
154 | * Get bookings ends between the given dates. |
||
155 | * |
||
156 | * @param string $starts |
||
157 | * @param string $ends |
||
158 | * |
||
159 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
160 | */ |
||
161 | public function bookingsEndsBetween(string $starts, string $ends): HasMany |
||
169 | |||
170 | /** |
||
171 | * Get bookings cancelled before the given date. |
||
172 | * |
||
173 | * @param string $date |
||
174 | * |
||
175 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
176 | */ |
||
177 | public function bookingsCancelledBefore(string $date): HasMany |
||
183 | |||
184 | /** |
||
185 | * Get bookings cancelled after the given date. |
||
186 | * |
||
187 | * @param string $date |
||
188 | * |
||
189 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
190 | */ |
||
191 | public function bookingsCancelledAfter(string $date): HasMany |
||
197 | |||
198 | /** |
||
199 | * Get bookings cancelled between the given dates. |
||
200 | * |
||
201 | * @param string $starts |
||
202 | * @param string $ends |
||
203 | * |
||
204 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
205 | */ |
||
206 | public function bookingsCancelledBetween(string $starts, string $ends): HasMany |
||
213 | |||
214 | /** |
||
215 | * Get bookings of the given model. |
||
216 | * |
||
217 | * @param string $bookable |
||
218 | * |
||
219 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
220 | */ |
||
221 | public function bookingsOf(string $bookable): HasMany |
||
226 | |||
227 | /** |
||
228 | * Check if the person booked the given model. |
||
229 | * |
||
230 | * @param \Illuminate\Database\Eloquent\Model $model |
||
231 | * |
||
232 | * @return bool |
||
233 | */ |
||
234 | public function isBooked(Model $model): bool |
||
238 | |||
239 | /** |
||
240 | * Book the given model at the given dates with the given price. |
||
241 | * |
||
242 | * @param \Illuminate\Database\Eloquent\Model $bookable |
||
243 | * @param string $starts |
||
244 | * @param string $ends |
||
245 | * @param float $price |
||
246 | * |
||
247 | * @return \Rinvex\Bookings\Models\Booking |
||
248 | */ |
||
249 | public function newBooking(Model $bookable, string $starts, string $ends, float $price): Booking |
||
260 | } |
||
261 |
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.