From 2c7a71a2a15d813adcfe91bc4550433426549a10 Mon Sep 17 00:00:00 2001 From: Terrell Eaton Date: Mon, 1 Nov 2021 22:14:19 +0100 Subject: [PATCH] Fixes not being able to search by checked out user in advanced search --- app/Models/Asset.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index fc0f8cc357..7be424077d 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1357,8 +1357,8 @@ class Asset extends Depreciable }); } - if ($fieldname == 'checkedout_to') { - $query->whereHas('assigneduser', function ($query) use ($search_val) { + if ($fieldname =='assigned_to') { + $query->whereHasMorph('assignedTo', [User::class], function ($query) use ($search_val) { $query->where(function ($query) use ($search_val) { $query->where('users.first_name', 'LIKE', '%'.$search_val.'%') ->orWhere('users.last_name', 'LIKE', '%'.$search_val.'%'); @@ -1421,7 +1421,7 @@ class Asset extends Depreciable }); }); } - } + /** * THIS CLUNKY BIT IS VERY IMPORTANT @@ -1447,11 +1447,11 @@ class Asset extends Depreciable */ if (($fieldname!='category') && ($fieldname!='model_number') && ($fieldname!='rtd_location') && ($fieldname!='location') && ($fieldname!='supplier') - && ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) { + && ($fieldname!='status_label') && ($fieldname!='assigned_to') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) { $query->where('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%'); } - + } });