Fixed advanced search on supplier, count for PHP7.2

This commit is contained in:
snipe 2018-04-25 20:25:03 -07:00
parent e5121b33e6
commit 5365182c86
2 changed files with 12 additions and 3 deletions

View file

@ -85,7 +85,7 @@ class AssetsController extends Controller
$filter = array(); $filter = array();
if ($request->has('filter')) { if ($request->has('filter')) {
$filter = json_decode($request->input('filter')); $filter = json_decode($request->input('filter'), true);
} }
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
@ -217,7 +217,8 @@ class AssetsController extends Controller
} }
if (count($filter) > 0) {
if ((!is_null($filter)) && (count($filter)) > 0) {
$assets->ByFilter($filter); $assets->ByFilter($filter);
} elseif ($request->has('search')) { } elseif ($request->has('search')) {
$assets->TextSearch($request->input('search')); $assets->TextSearch($request->input('search'));

View file

@ -1050,9 +1050,17 @@ class Asset extends Depreciable
}); });
}); });
} }
if ($fieldname =='supplier') {
$query->where(function ($query) use ($search_val) {
$query->whereHas('supplier', function ($query) use ($search_val) {
$query->where('suppliers.name', 'LIKE', '%' . $search_val . '%');
});
});
}
} }
if (($fieldname!='category') && ($fieldname!='location') if (($fieldname!='category') && ($fieldname!='location') && ($fieldname!='supplier')
&& ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) { && ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) {
$query->orWhere('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%'); $query->orWhere('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%');
} }