Skip to content

Commit

Permalink
fix messages pagination issue by using whereHas method
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid committed Dec 5, 2016
1 parent 58360fe commit 0af2277
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "nahid/talk",
"description": "Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=",
"description": "Talk is a Laravel 5 based users conversations library. It helps to develop users messages and conversations in easy way.",
"keywords": ["message", "inbox", "conversations", "chat", "php", "laravel"],
"homepage": "https://github.com/nahid/talk",
"type": "library",
"license": "CC(3.0)",
"authors": [
{
Expand Down
19 changes: 10 additions & 9 deletions src/Conversations/ConversationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ public function threadsAll($user, $offset, $take)
* */
public function getMessagesById($conversationId, $userId, $offset, $take)
{
return $this->with(['messages' => function ($q) use ($userId, $offset, $take) {
return $q->where(function ($q) use ($userId) {
$q->where('user_id', $userId)
->where('deleted_from_sender', 0);
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);
$q->where('deleted_from_receiver', 0);
})->offset($offset)->take($take);
}, 'userone', 'usertwo'])->find($conversationId);
->orWhere(function ($q) use ($userId) {
$q->where('user_id', '!=', $userId)
->where('deleted_from_receiver', 0);
})->skip($offset)->take($take);
})->with(['userone', 'usertwo'])->find($conversationId);

}

/*
Expand Down
1 change: 1 addition & 0 deletions src/TalkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function registerTalk()
return new Talk($app[ConversationRepository::class], $app[MessageRepository::class]);
});
}

/**
* Get the services provided by the provider.
*
Expand Down

0 comments on commit 0af2277

Please sign in to comment.