Inheritance: extends Illuminate\Database\Eloquent\Model
Exemplo n.º 1
0
 public function threadsAll($user, $offset, $take)
 {
     $msgThread = Conversation::with(['messages' => function ($q) use($user) {
         return $q->latest();
     }, 'userone', 'usertwo'])->where('user_one', $user)->orWhere('user_two', $user)->offset($offset)->take($take)->get();
     $threads = [];
     foreach ($msgThread as $thread) {
         $conversationWith = $thread->userone->id == $user ? $thread->usertwo : $thread->userone;
         $message = $thread->messages->first();
         $message->user = $conversationWith;
         $threads[] = $message;
     }
     return collect($threads);
 }
Exemplo n.º 2
0
 public function getMessagesById($conversationId, $userId, $offset, $take)
 {
     return Conversation::whereHas('messages', function ($query) use($userId, $offset, $take) {
         $query->where(function ($qr) use($userId) {
             $qr->where('user_id', '=', $userId)->where('deleted_from_sender', 0);
         })->orWhere(function ($q) use($userId) {
             $q->where('user_id', '!=', $userId)->where('deleted_from_receiver', 0);
         })->skip($offset)->take($take);
     })->with(['userone', 'usertwo'])->find($conversationId);
 }