1 | <?php namespace Arcanedev\LaravelMessenger\Models; |
||
34 | class Discussion extends Model implements DiscussionContract |
||
35 | { |
||
36 | /* ------------------------------------------------------------------------------------------------ |
||
37 | | Traits |
||
38 | | ------------------------------------------------------------------------------------------------ |
||
39 | */ |
||
40 | use SoftDeletes; |
||
41 | |||
42 | /* ------------------------------------------------------------------------------------------------ |
||
43 | | Properties |
||
44 | | ------------------------------------------------------------------------------------------------ |
||
45 | */ |
||
46 | /** |
||
47 | * The attributes that can be set with Mass Assignment. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $fillable = ['subject']; |
||
52 | |||
53 | /** |
||
54 | * The attributes that should be mutated to dates. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $dates = ['deleted_at']; |
||
59 | |||
60 | /** |
||
61 | * The attributes that should be cast to native types. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $casts = [ |
||
66 | 'id' => 'integer', |
||
67 | ]; |
||
68 | |||
69 | /* ------------------------------------------------------------------------------------------------ |
||
70 | | Constructor |
||
71 | | ------------------------------------------------------------------------------------------------ |
||
72 | */ |
||
73 | /** |
||
74 | * Create a new Eloquent model instance. |
||
75 | * |
||
76 | * @param array $attributes |
||
77 | */ |
||
78 | 304 | public function __construct(array $attributes = []) |
|
86 | |||
87 | /* ------------------------------------------------------------------------------------------------ |
||
88 | | Relationships |
||
89 | | ------------------------------------------------------------------------------------------------ |
||
90 | */ |
||
91 | /** |
||
92 | * Participants relationship. |
||
93 | * |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
95 | */ |
||
96 | 216 | public function participants() |
|
102 | |||
103 | /** |
||
104 | * Messages relationship. |
||
105 | * |
||
106 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
107 | */ |
||
108 | 88 | public function messages() |
|
114 | |||
115 | /** |
||
116 | * Get the user that created the first message. |
||
117 | * |
||
118 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
119 | */ |
||
120 | 8 | public function creator() |
|
124 | |||
125 | /* ------------------------------------------------------------------------------------------------ |
||
126 | | Scopes |
||
127 | | ------------------------------------------------------------------------------------------------ |
||
128 | */ |
||
129 | /** |
||
130 | * Scope discussions that the user is associated with. |
||
131 | * |
||
132 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
133 | * @param int $userId |
||
134 | * |
||
135 | * @return \Illuminate\Database\Eloquent\Builder |
||
136 | */ |
||
137 | 16 | public function scopeForUser(Builder $query, $userId) |
|
148 | |||
149 | /** |
||
150 | * Scope discussions with new messages that the user is associated with. |
||
151 | * |
||
152 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
153 | * @param int $userId |
||
154 | * |
||
155 | * @return \Illuminate\Database\Eloquent\Builder |
||
156 | */ |
||
157 | 8 | public function scopeForUserWithNewMessages(Builder $query, $userId) |
|
171 | |||
172 | /** |
||
173 | * Scope discussions between given user ids. |
||
174 | * |
||
175 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
176 | * @param array $userIds |
||
177 | * |
||
178 | * @return \Illuminate\Database\Eloquent\Builder |
||
179 | */ |
||
180 | 8 | public function scopeBetween(Builder $query, array $userIds) |
|
190 | |||
191 | /** |
||
192 | * Get the participants table name. |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | 24 | protected function getParticipantsTable() |
|
200 | |||
201 | /** |
||
202 | * Scope the query by the subject. |
||
203 | * |
||
204 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
205 | * @param string $subject |
||
206 | * @param bool $strict |
||
207 | * |
||
208 | * @return \Illuminate\Database\Eloquent\Builder |
||
209 | */ |
||
210 | 16 | public function scopeSubject(Builder $query, $subject, $strict = false) |
|
216 | |||
217 | /* ------------------------------------------------------------------------------------------------ |
||
218 | | Getters & Setters |
||
219 | | ------------------------------------------------------------------------------------------------ |
||
220 | */ |
||
221 | /** |
||
222 | * Get the latest_message attribute. |
||
223 | * |
||
224 | * @return \Arcanedev\LaravelMessenger\Models\Message |
||
225 | */ |
||
226 | 8 | public function getLatestMessageAttribute() |
|
230 | |||
231 | /* ------------------------------------------------------------------------------------------------ |
||
232 | | Main Functions |
||
233 | | ------------------------------------------------------------------------------------------------ |
||
234 | */ |
||
235 | /** |
||
236 | * Returns all of the latest discussions by `updated_at` date. |
||
237 | * |
||
238 | * @return \Illuminate\Database\Eloquent\Collection |
||
239 | */ |
||
240 | 8 | public static function getLatest() |
|
244 | |||
245 | /** |
||
246 | * Returns all discussions by subject. |
||
247 | * |
||
248 | * @param string $subject |
||
249 | * @param bool $strict |
||
250 | * |
||
251 | * @return \Illuminate\Database\Eloquent\Collection |
||
252 | */ |
||
253 | 16 | public static function getBySubject($subject, $strict = false) |
|
257 | |||
258 | /** |
||
259 | * Returns an array of user ids that are associated with the discussion. |
||
260 | * |
||
261 | * @param int|null $userId |
||
262 | * |
||
263 | * @return \Illuminate\Support\Collection |
||
264 | */ |
||
265 | 8 | public function participantsUserIds($userId = null) |
|
272 | |||
273 | /** |
||
274 | * Add a user to discussion as a participant. |
||
275 | * |
||
276 | * @param int $userId |
||
277 | * |
||
278 | * @return \Arcanedev\LaravelMessenger\Models\Participant |
||
279 | */ |
||
280 | 112 | public function addParticipant($userId) |
|
290 | |||
291 | /** |
||
292 | * Add users to discussion as participants. |
||
293 | * |
||
294 | * @param array $userIds |
||
295 | * |
||
296 | * @return \Illuminate\Database\Eloquent\Collection |
||
297 | */ |
||
298 | 64 | public function addParticipants(array $userIds) |
|
306 | |||
307 | /** |
||
308 | * Remove a participant from discussion. |
||
309 | * |
||
310 | * @param int $userId |
||
311 | * @param bool $reload |
||
312 | * |
||
313 | * @return int |
||
314 | */ |
||
315 | 16 | public function removeParticipant($userId, $reload = true) |
|
319 | |||
320 | /** |
||
321 | * Remove participants from discussion. |
||
322 | * |
||
323 | * @param array $userIds |
||
324 | * @param bool $reload |
||
325 | * |
||
326 | * @return int |
||
327 | */ |
||
328 | 48 | public function removeParticipants(array $userIds, $reload = true) |
|
339 | |||
340 | /** |
||
341 | * Mark a discussion as read for a user. |
||
342 | * |
||
343 | * @param int $userId |
||
344 | * |
||
345 | * @return bool|int |
||
346 | */ |
||
347 | 40 | public function markAsRead($userId) |
|
357 | |||
358 | /** |
||
359 | * See if the current thread is unread by the user. |
||
360 | * |
||
361 | * @param int $userId |
||
362 | * |
||
363 | * @return bool |
||
364 | */ |
||
365 | 16 | public function isUnread($userId) |
|
371 | |||
372 | /** |
||
373 | * Finds the participant record from a user id. |
||
374 | * |
||
375 | * @param int $userId |
||
376 | * |
||
377 | * @return \Arcanedev\LaravelMessenger\Models\Participant |
||
378 | */ |
||
379 | 56 | public function getParticipantByUserId($userId) |
|
385 | |||
386 | /** |
||
387 | * Get the trashed participants. |
||
388 | * |
||
389 | * @return \Illuminate\Database\Eloquent\Collection |
||
390 | */ |
||
391 | 16 | public function getTrashedParticipants() |
|
397 | |||
398 | /** |
||
399 | * Restores all participants within a discussion. |
||
400 | * |
||
401 | * @param bool $reload |
||
402 | * |
||
403 | * @return int |
||
404 | */ |
||
405 | 8 | public function restoreAllParticipants($reload = true) |
|
416 | |||
417 | /** |
||
418 | * Generates a participant information as a string. |
||
419 | * |
||
420 | * @param int|null $ignoredUserId |
||
421 | * @param \Closure|null $callback |
||
422 | * @param string $glue |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | 16 | public function participantsString($ignoredUserId = null, $callback = null, $glue = ', ') |
|
442 | |||
443 | /** |
||
444 | * Checks to see if a user is a current participant of the discussion. |
||
445 | * |
||
446 | * @param int $userId |
||
447 | * |
||
448 | * @return bool |
||
449 | */ |
||
450 | 16 | public function hasParticipant($userId) |
|
456 | |||
457 | /** |
||
458 | * Returns array of unread messages in discussion for given user. |
||
459 | * |
||
460 | * @param int $userId |
||
461 | * |
||
462 | * @return \Illuminate\Support\Collection |
||
463 | */ |
||
464 | 16 | public function userUnreadMessages($userId) |
|
476 | } |
||
477 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: