From a7de97f06062106da886d14be22b343e17f25ed9 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 10 Aug 2022 19:13:28 -0500 Subject: [PATCH] Found a better place for the where condition --- app/Models/Traits/Searchable.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php index 3c493b4a81..ffe7e05a1d 100644 --- a/app/Models/Traits/Searchable.php +++ b/app/Models/Traits/Searchable.php @@ -161,11 +161,12 @@ trait Searchable } $query->orWhere($table.'.'.$column, 'LIKE', '%'.$term.'%'); - if($table == 'users'){ - $query->orWhereRaw('CONCAT(users.first_name ," ", users.last_name) LIKE ?', ["%$term%"]); - } } } + // I put this here because I only want to add the concat one time in the end of the user relation search + if($relation == 'user') { + $query->orWhereRaw('CONCAT (users.first_name, " ", users.last_name) LIKE ?', ["%$term%"]); + } }); }