-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any way to query specific types of messages #280
Comments
if you wish use eloquent Chat::where() or scope You can generate queries of your own. dont forget |
You can reuse the chat/src/Models/Conversation.php Line 319 in a229349
Like this: $conversation = Chat::conversations()->getById(request('id'));
$tablePrefix = 'chat_';
$paginationParams = [
'pageName' => 'page',
'page' => request('page') ? request('page') : 1,
'perPage' => 10,
'sorting' => "desc"
];
$message_types = array(); // <- Add message types to this array
$messages = Chat::conversation($conversation)->setParticipant($user)
->conversation
->messages()
->join($tablePrefix.'message_notifications', $tablePrefix.'message_notifications.message_id', '=', $tablePrefix.'messages.id')
->where($tablePrefix.'message_notifications.messageable_type', $user->getMorphClass())
->where($tablePrefix.'message_notifications.messageable_id', $user->getKey())
->when(!empty($message_types), function($query) use ($message_types) {
$query->whereIn('type', $message_types);
})
->orderBy($tablePrefix.'messages.id', $paginationParams['sorting'])
->paginate(
$paginationParams['perPage'],
[
$tablePrefix.'message_notifications.updated_at as read_at',
$tablePrefix.'message_notifications.deleted_at as deleted_at',
$tablePrefix.'message_notifications.messageable_id',
$tablePrefix.'message_notifications.id as notification_id',
$tablePrefix.'message_notifications.is_seen',
$tablePrefix.'message_notifications.is_sender',
$tablePrefix.'messages.*',
],
$paginationParams['pageName'],
$paginationParams['page']
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: