You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for creating such a nice package.
I have come across an unexpected behaviour in Laravel 5.3.
FYI: I am using latest release of this package
Only can sender load messages for a conversation from the db, the receiver cannot load messages from the db so I dig into the source code.
Found that the getMessagesById function in ConversationRepository.php file has the following query for the eager loading relations of messages.
return Conversation::with(['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);
});
$query->offset($offset)->take($take);
}])->with(['userone', 'usertwo'])->find($conversationId);
which translates to select * from messages where conversation_id in ($conversationId) and (user_id = $userId and deleted_from_sender = 0) or (user_id != $userId and deleted_from_receiver = 0).
Actually the query should look like this select * from messages where conversation_id in ($conversationId) and ((user_id = $userId and deleted_from_sender = 0) or (user_id != $userId and deleted_from_receiver = 0))
and the code for the passed callback function for the message relations do the trick
$query->where(function ($qr) use ($userId) {
$qr->where(function ($q) use ($userId) {
$q->where('user_id', '=', $userId)
->where('deleted_from_sender', 0);
})
->orWhere(function ($q) use ($userId) {
$q->where('user_id', '!=', $userId)
->where('deleted_from_receiver', 0);
});
});
});
I don't know if it was the issue of Laravel 5.3. Please review. Thanks.
The text was updated successfully, but these errors were encountered:
First of all, thanks for creating such a nice package.
I have come across an unexpected behaviour in Laravel 5.3.
FYI: I am using latest release of this package
Only can sender load messages for a conversation from the db, the receiver cannot load messages from the db so I dig into the source code.
Found that the
getMessagesById
function inConversationRepository.php
file has the following query for the eager loading relations of messages.which translates to
select * from messages where conversation_id in ($conversationId) and (user_id = $userId and deleted_from_sender = 0) or (user_id != $userId and deleted_from_receiver = 0)
.Actually the query should look like this
select * from messages where conversation_id in ($conversationId) and ((user_id = $userId and deleted_from_sender = 0) or (user_id != $userId and deleted_from_receiver = 0))
and the code for the passed callback function for the message relations do the trick
I don't know if it was the issue of Laravel 5.3. Please review. Thanks.
The text was updated successfully, but these errors were encountered: