Skip to content

Commit 550790b

Browse files
committed
add participants relation, formatting
1 parent 86db6af commit 550790b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Cmgmyr/Messenger/Traits/Messagable.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Cmgmyr\Messenger\Traits;
44

5-
use Cmgmyr\Messenger\Models\Thread;
6-
75
trait Messagable
86
{
97
/**
@@ -16,6 +14,16 @@ public function messages()
1614
return $this->hasMany(config('messenger.message_model'));
1715
}
1816

17+
/**
18+
* Participants relationship.
19+
*
20+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
21+
*/
22+
public function participants()
23+
{
24+
return $this->hasMany(config('messenger.participant_model'));
25+
}
26+
1927
/**
2028
* Thread relationship.
2129
*
@@ -46,7 +54,7 @@ public function threadsWithNewMessages()
4654
$threadsWithNewMessages = [];
4755

4856
$participantModelClass = config('messenger.participant_model');
49-
$participantModel = new $participantModelClass;
57+
$participantModel = new $participantModelClass;
5058

5159
$participants = $participantModel->where('user_id', $this->id)->lists('last_read', 'thread_id');
5260

@@ -62,7 +70,7 @@ public function threadsWithNewMessages()
6270

6371
if ($participants) {
6472
$threadModelClass = config('messenger.thread_model');
65-
$threadModel = new $threadModelClass;
73+
$threadModel = new $threadModelClass;
6674

6775
$threads = $threadModel->whereIn('id', array_keys($participants))->get();
6876

@@ -76,6 +84,11 @@ public function threadsWithNewMessages()
7684
return $threadsWithNewMessages;
7785
}
7886

87+
/**
88+
* Returns the "participants" table name to use in manual queries.
89+
*
90+
* @return string
91+
*/
7992
private function getParticipantTable()
8093
{
8194
$participantModel = config('messenger.participant_model');

0 commit comments

Comments
 (0)