public function getMessagesById($conversationId, $offset, $take) { return $this->with(['messages' => function ($q) use($offset, $take) { $q->offset($offset); $q->take($take); }, 'userone', 'usertwo'])->find($conversationId); }
/** * fetch all conversation by using coversation id. * * @param int $conversationId * @param int $offset = 0 * @param int $take = 20 * @return \Nahid\Talk\Messages\Message */ public function getConversationsById($conversationId, $offset = 0, $take = 20) { $conversations = $this->conversation->getMessagesById($conversationId, $offset, $take); $collection = (object) null; if ($conversations->user_one == $this->authUserId || $conversations->user_two == $this->authUserId) { $withUser = $conversations->userone->id === $this->authUserId ? $conversations->usertwo : $conversations->userone; $collection->withUser = $withUser; $collection->messages = $conversations->messages; return $collection; } return false; }