1 | <?php |
||
37 | class Discussion extends Model implements DiscussionContract |
||
38 | { |
||
39 | /* ----------------------------------------------------------------- |
||
40 | | Properties |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * The attributes that can be set with Mass Assignment. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $fillable = ['subject']; |
||
50 | |||
51 | /** |
||
52 | * The attributes that should be mutated to dates. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $dates = ['deleted_at']; |
||
57 | |||
58 | /** |
||
59 | * The attributes that should be cast to native types. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $casts = [ |
||
64 | 'id' => 'integer', |
||
65 | ]; |
||
66 | |||
67 | /* ----------------------------------------------------------------- |
||
68 | | Constructor |
||
69 | | ----------------------------------------------------------------- |
||
70 | */ |
||
71 | |||
72 | /** |
||
73 | * Create a new Eloquent model instance. |
||
74 | * |
||
75 | * @param array $attributes |
||
76 | */ |
||
77 | 240 | public function __construct(array $attributes = []) |
|
85 | |||
86 | /* ----------------------------------------------------------------- |
||
87 | | Relationships |
||
88 | | ----------------------------------------------------------------- |
||
89 | */ |
||
90 | |||
91 | /** |
||
92 | * Participants relationship. |
||
93 | * |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
95 | */ |
||
96 | 168 | public function participations() |
|
102 | |||
103 | /** |
||
104 | * Messages relationship. |
||
105 | * |
||
106 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
107 | */ |
||
108 | 66 | public function messages() |
|
114 | |||
115 | /** |
||
116 | * Get the participable that created the first message. |
||
117 | * |
||
118 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
119 | */ |
||
120 | 6 | public function creator() |
|
124 | |||
125 | /* ----------------------------------------------------------------- |
||
126 | | Scopes |
||
127 | | ----------------------------------------------------------------- |
||
128 | */ |
||
129 | |||
130 | /** |
||
131 | * Scope discussions that the participable is associated with. |
||
132 | * |
||
133 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
134 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
135 | * |
||
136 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
137 | */ |
||
138 | 12 | public function scopeForUser(Builder $query, EloquentModel $participable) |
|
150 | |||
151 | /** |
||
152 | * Scope discussions with new messages that the participable is associated with. |
||
153 | * |
||
154 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
155 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
156 | * |
||
157 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
158 | */ |
||
159 | 6 | public function scopeForUserWithNewMessages(Builder $query, EloquentModel $participable) |
|
173 | |||
174 | /** |
||
175 | * Scope discussions between given participables. |
||
176 | * |
||
177 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
178 | * @param \Illuminate\Support\Collection|array $participables |
||
179 | * |
||
180 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
181 | */ |
||
182 | 6 | public function scopeBetween(Builder $query, $participables) |
|
204 | |||
205 | /** |
||
206 | * Scope the query by the subject. |
||
207 | * |
||
208 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
209 | * @param string $subject |
||
210 | * @param bool $strict |
||
211 | * |
||
212 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
213 | */ |
||
214 | 12 | public function scopeSubject(Builder $query, $subject, $strict = false) |
|
218 | |||
219 | /* ----------------------------------------------------------------- |
||
220 | | Getters & Setters |
||
221 | | ----------------------------------------------------------------- |
||
222 | */ |
||
223 | |||
224 | /** |
||
225 | * Get the latest_message attribute. |
||
226 | * |
||
227 | * @return \Arcanedev\LaravelMessenger\Models\Message |
||
228 | */ |
||
229 | 6 | public function getLatestMessageAttribute() |
|
233 | |||
234 | /** |
||
235 | * Get the participations table name. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | 18 | protected function getParticipationsTable() |
|
243 | |||
244 | /* ----------------------------------------------------------------- |
||
245 | | Main Methods |
||
246 | | ----------------------------------------------------------------- |
||
247 | */ |
||
248 | |||
249 | /** |
||
250 | * Returns all of the latest discussions by `updated_at` date. |
||
251 | * |
||
252 | * @return \Illuminate\Database\Eloquent\Collection |
||
253 | */ |
||
254 | 6 | public static function getLatest() |
|
258 | |||
259 | /** |
||
260 | * Returns all discussions by subject. |
||
261 | * |
||
262 | * @param string $subject |
||
263 | * @param bool $strict |
||
264 | * |
||
265 | * @return \Illuminate\Database\Eloquent\Collection |
||
266 | */ |
||
267 | 12 | public static function getBySubject($subject, $strict = false) |
|
271 | |||
272 | /** |
||
273 | * Returns an array of participables that are associated with the discussion. |
||
274 | * |
||
275 | * @return \Illuminate\Database\Eloquent\Collection |
||
276 | */ |
||
277 | 12 | public function getParticipables() |
|
289 | |||
290 | /** |
||
291 | * Add a participable to discussion. |
||
292 | * |
||
293 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
294 | * |
||
295 | * @return \Arcanedev\LaravelMessenger\Models\Participation|mixed |
||
296 | */ |
||
297 | 84 | public function addParticipant(EloquentModel $participable) |
|
307 | |||
308 | /** |
||
309 | * Add many participables to discussion. |
||
310 | * |
||
311 | * @param \Illuminate\Support\Collection|array $participables |
||
312 | * |
||
313 | * @return \Illuminate\Database\Eloquent\Collection |
||
314 | */ |
||
315 | 48 | public function addParticipants($participables) |
|
323 | |||
324 | /** |
||
325 | * Remove a participable from discussion. |
||
326 | * |
||
327 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
328 | * @param bool $reload |
||
329 | * |
||
330 | * @return int |
||
331 | */ |
||
332 | 12 | public function removeParticipant(EloquentModel $participable, $reload = true) |
|
336 | |||
337 | /** |
||
338 | * Remove many participables from discussion. |
||
339 | * |
||
340 | * @param \Illuminate\Support\Collection|array $participables |
||
341 | * @param bool $reload |
||
342 | * |
||
343 | * @return int |
||
344 | */ |
||
345 | 36 | public function removeParticipants($participables, $reload = true) |
|
364 | |||
365 | /** |
||
366 | * Mark a discussion as read for a participable. |
||
367 | * |
||
368 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
369 | * |
||
370 | * @return bool|int |
||
371 | */ |
||
372 | 30 | public function markAsRead(EloquentModel $participable) |
|
380 | |||
381 | /** |
||
382 | * See if the current thread is unread by the participable. |
||
383 | * |
||
384 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
385 | * |
||
386 | * @return bool |
||
387 | */ |
||
388 | 12 | public function isUnread(EloquentModel $participable) |
|
394 | |||
395 | /** |
||
396 | * Finds the participant record from a participable model. |
||
397 | * |
||
398 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
399 | * |
||
400 | * @return \Arcanedev\LaravelMessenger\Models\Participation|mixed |
||
401 | */ |
||
402 | 42 | public function getParticipationByParticipable(EloquentModel $participable) |
|
411 | |||
412 | /** |
||
413 | * Get the trashed participations. |
||
414 | * |
||
415 | * @return \Illuminate\Database\Eloquent\Collection |
||
416 | */ |
||
417 | 12 | public function getTrashedParticipations() |
|
421 | |||
422 | /** |
||
423 | * Restores all participations within a discussion. |
||
424 | * |
||
425 | * @param bool $reload |
||
426 | * |
||
427 | * @return int |
||
428 | */ |
||
429 | 6 | public function restoreAllParticipations($reload = true) |
|
442 | |||
443 | /** |
||
444 | * Generates a participant information as a string. |
||
445 | * |
||
446 | * @param \Closure|null $callback |
||
447 | * @param string $glue |
||
448 | * |
||
449 | * @return string |
||
450 | */ |
||
451 | 12 | public function participationsString($callback = null, $glue = ', ') |
|
465 | |||
466 | /** |
||
467 | * Checks to see if a participable is a current participant of the discussion. |
||
468 | * |
||
469 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
470 | * |
||
471 | * @return bool |
||
472 | */ |
||
473 | 12 | public function hasParticipation(EloquentModel $participable) |
|
482 | |||
483 | /** |
||
484 | * Get the unread messages in discussion for a specific participable. |
||
485 | * |
||
486 | * @param \Illuminate\Database\Eloquent\Model $participable |
||
487 | * |
||
488 | * @return \Illuminate\Support\Collection |
||
489 | */ |
||
490 | 12 | public function getUnreadMessages(EloquentModel $participable) |
|
503 | } |
||
504 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: