@@ -11,7 +11,7 @@ trait Messagable
11
11
*/
12
12
public function messages ()
13
13
{
14
- return $ this ->hasMany (Config:: get ('messenger.message_model ' ));
14
+ return $ this ->hasMany (config ('messenger.message_model ' ));
15
15
}
16
16
17
17
/**
@@ -21,7 +21,7 @@ public function messages()
21
21
*/
22
22
public function threads ()
23
23
{
24
- return $ this ->belongsToMany (Config:: get ('messenger.thread_model ' ), ' participants ' );
24
+ return $ this ->belongsToMany (config ('messenger.thread_model ' ), $ this -> getParticipantTable (), ' user_id ' , ' thread_id ' );
25
25
}
26
26
27
27
/**
@@ -54,23 +54,33 @@ public function threadsWithNewMessages()
54
54
* I don't want to include as a dependency for this package...it's overkill. So let's
55
55
* exclude this check in the testing environment.
56
56
*/
57
- if (getenv ('APP_ENV ' ) == 'testing ' || !str_contains (\Illuminate \Foundation \Application::VERSION , '5.0 ' )) {
57
+ if (getenv ('APP_ENV ' ) == 'testing ' || !str_contains (\Illuminate \Foundation \Application::VERSION , '5.0 ' ))
58
+ {
58
59
$ participants = $ participants ->all ();
59
60
}
60
61
61
- if ($ participants ) {
62
+ if ($ participants )
63
+ {
62
64
$ threadModelClass = config ('messenger.thread_model ' );
63
65
$ threadModel = new $ threadModelClass ;
64
66
65
67
$ threads = $ threadModel ->whereIn ('id ' , array_keys ($ participants ))->get ();
66
68
67
- foreach ($ threads as $ thread ) {
68
- if ($ thread ->updated_at > $ participants [$ thread ->id ]) {
69
+ foreach ($ threads as $ thread )
70
+ {
71
+ if ($ thread ->updated_at > $ participants [$ thread ->id ])
72
+ {
69
73
$ threadsWithNewMessages [] = $ thread ->id ;
70
74
}
71
75
}
72
76
}
73
77
74
78
return $ threadsWithNewMessages ;
75
79
}
80
+
81
+ private function getParticipantTable ()
82
+ {
83
+ $ participantModel = config ('messenger.participant_model ' );
84
+ return (new $ participantModel )->getTable ();
85
+ }
76
86
}
0 commit comments