2
2
3
3
namespace Cmgmyr \Messenger \Traits ;
4
4
5
- use Cmgmyr \Messenger \Models \Thread ;
6
-
7
5
trait Messagable
8
6
{
9
7
/**
@@ -16,6 +14,16 @@ public function messages()
16
14
return $ this ->hasMany (config ('messenger.message_model ' ));
17
15
}
18
16
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
+
19
27
/**
20
28
* Thread relationship.
21
29
*
@@ -46,7 +54,7 @@ public function threadsWithNewMessages()
46
54
$ threadsWithNewMessages = [];
47
55
48
56
$ participantModelClass = config ('messenger.participant_model ' );
49
- $ participantModel = new $ participantModelClass ;
57
+ $ participantModel = new $ participantModelClass ;
50
58
51
59
$ participants = $ participantModel ->where ('user_id ' , $ this ->id )->lists ('last_read ' , 'thread_id ' );
52
60
@@ -62,7 +70,7 @@ public function threadsWithNewMessages()
62
70
63
71
if ($ participants ) {
64
72
$ threadModelClass = config ('messenger.thread_model ' );
65
- $ threadModel = new $ threadModelClass ;
73
+ $ threadModel = new $ threadModelClass ;
66
74
67
75
$ threads = $ threadModel ->whereIn ('id ' , array_keys ($ participants ))->get ();
68
76
@@ -76,6 +84,11 @@ public function threadsWithNewMessages()
76
84
return $ threadsWithNewMessages ;
77
85
}
78
86
87
+ /**
88
+ * Returns the "participants" table name to use in manual queries.
89
+ *
90
+ * @return string
91
+ */
79
92
private function getParticipantTable ()
80
93
{
81
94
$ participantModel = config ('messenger.participant_model ' );
0 commit comments