diff --git a/app/Helpers/SearchHelper.php b/app/Helpers/SearchHelper.php index c9bd101976f..de6c1f5ca0f 100644 --- a/app/Helpers/SearchHelper.php +++ b/app/Helpers/SearchHelper.php @@ -49,7 +49,7 @@ public static function searchContacts(string $needle, string $orderByColumn, str return Contact::search($needle, $accountId, $orderByColumn, $orderByDirection) ->notes($accountId, $needle) - ->introductionAdditionalInformation($needle) + ->introductionAdditionalInformation($accountId, $needle) ->addressBook($accountId, $addressBookName); } } diff --git a/app/Models/Contact/Contact.php b/app/Models/Contact/Contact.php index 40cb3d1c087..c162fea9f91 100644 --- a/app/Models/Contact/Contact.php +++ b/app/Models/Contact/Contact.php @@ -592,9 +592,11 @@ public function scopeNotActive($query) */ public function scopeNotes($query, int $accountId = null, string $needle) { - return $query->orWhereHas('notes', function ($query) use ($accountId, $needle) { + $maccountId = $accountId ?? Auth::user()->account_id; + + return $query->orWhereHas('notes', function ($query) use ($maccountId, $needle) { return $query->where([ - ['account_id', $accountId], + ['account_id', $maccountId], ['body', 'like', "%$needle%"], ]); }); @@ -606,9 +608,12 @@ public function scopeNotes($query, int $accountId = null, string $needle) * @param Builder $query * @return Builder */ - public function scopeIntroductionAdditionalInformation($query, string $needle) + public function scopeIntroductionAdditionalInformation($query, int $accountId = null, string $needle) { + $maccountId = $accountId ?? Auth::user()->account_id; + return $query->orWhere([ + ['account_id', $maccountId], ['first_met_additional_info', 'like', "%$needle%"], ]); }