File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ public function markAsReadBy(User|int $user, ?Carbon $date = null): static
139139 {
140140 $ userId = $ user instanceof User ? $ user ->getKey () : $ user ;
141141
142- $ read = $ this -> reads ()->firstOrNew ([
142+ $ read = static :: getModelRead ():: query ()->firstOrNew ([
143143 'user_id ' => $ userId ,
144144 'message_id ' => $ this ->id ,
145145 ]);
@@ -161,11 +161,19 @@ public function markAsUnreadBy(User|int $user): static
161161 {
162162 $ userId = $ user instanceof User ? $ user ->getKey () : $ user ;
163163
164- $ read = $ this ->reads ->firstWhere ('user_id ' , $ userId );
164+ $ read = static ::getModelRead ()::query ()->firstOrNew ([
165+ 'user_id ' => $ userId ,
166+ 'message_id ' => $ this ->id ,
167+ ]);
168+
169+ $ read ->read_at = null ;
170+ $ read ->save ();
165171
166- if ($ read ) {
167- $ read ->read_at = null ;
168- $ read ->save ();
172+ if ($ this ->relationLoaded ('reads ' )) {
173+ $ this ->setRelation (
174+ 'reads ' ,
175+ $ this ->reads ->except ([$ read ])->push ($ read )
176+ );
169177 }
170178
171179 return $ this ;
You can’t perform that action at this time.
0 commit comments