From 5a182b4532513a73e54b167577c5a58e98d1810b Mon Sep 17 00:00:00 2001 From: choirool Date: Thu, 19 Aug 2021 10:39:08 +0800 Subject: [PATCH 1/2] Search keyword for user on conversation list --- src/Models/Conversation.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Models/Conversation.php b/src/Models/Conversation.php index 941284ca..f69665e2 100644 --- a/src/Models/Conversation.php +++ b/src/Models/Conversation.php @@ -386,8 +386,17 @@ private function getConversationsList(Model $participant, $options) } if (isset($options['filters']['keyword']) && $options['filters']['keyword'] !== '') { - $paginator->whereHas('conversation.messages', function ($query) use ($options) { - $query->where('body', 'like', "%{$options['filters']['keyword']}%"); + $paginator->where(function ($query) use ($participant, $options) { + $query->whereHas('conversation.messages', function ($query) use ($options) { + $query->where('body', 'like', "%{$options['filters']['keyword']}%"); + }) + ->orWhereHas('conversation.participants.messageable', function ($query) use ($participant, $options) { + $query->where(function ($query) use ($options) { + $query->where('firstname', 'like', "%{$options['filters']['keyword']}%") + ->orWhere('lastname', 'like', "%{$options['filters']['keyword']}%"); + }) + ->where('messageable_id', '<>', $participant->id); + }); }); } From 28694497939ce7ca53d3a837d46031a2a7aedb09 Mon Sep 17 00:00:00 2001 From: choirool Date: Thu, 19 Aug 2021 10:40:29 +0800 Subject: [PATCH 2/2] Search particiant name on conversation --- src/Models/Conversation.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Models/Conversation.php b/src/Models/Conversation.php index f69665e2..6f6a269c 100644 --- a/src/Models/Conversation.php +++ b/src/Models/Conversation.php @@ -391,11 +391,11 @@ private function getConversationsList(Model $participant, $options) $query->where('body', 'like', "%{$options['filters']['keyword']}%"); }) ->orWhereHas('conversation.participants.messageable', function ($query) use ($participant, $options) { - $query->where(function ($query) use ($options) { - $query->where('firstname', 'like', "%{$options['filters']['keyword']}%") - ->orWhere('lastname', 'like', "%{$options['filters']['keyword']}%"); - }) - ->where('messageable_id', '<>', $participant->id); + $query->where('messageable_id', '<>', $participant->id) + ->where(function ($query) use ($options) { + $query->where('firstname', 'like', "%{$options['filters']['keyword']}%") + ->orWhere('lastname', 'like', "%{$options['filters']['keyword']}%"); + }); }); }); }