diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 501a2d7f49..060946d9d5 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -189,18 +189,18 @@ class AssetModelsController extends Controller 'models.image', 'models.model_number', 'models.manufacturer_id', - ])->with('manufacturer')->OrderManufacturer('ASC'); + 'models.category_id', + ])->with('manufacturer','category'); if ($request->has('search')) { - $assetmodels = $assetmodels->where('models.name', 'LIKE', '%'.$request->get('search').'%') - ->orWhere('models.model_number', 'LIKE', '%'.$request->get('search').'%'); + $assetmodels = $assetmodels->SearchByManufacturerOrCat($request->input('search')); } - $assetmodels = $assetmodels->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50); + $assetmodels = $assetmodels->OrderCategory('ASC')->OrderManufacturer('ASC')->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50); foreach ($assetmodels as $assetmodel) { - $assetmodel->use_text = (($assetmodel->manufacturer) ? e($assetmodel->manufacturer->name) : '').' '.$assetmodel->present()->modelName; + $assetmodel->use_text = (($assetmodel->category) ? e($assetmodel->category->name) : '').': '.(($assetmodel->manufacturer) ? e($assetmodel->manufacturer->name) : '').' '.$assetmodel->present()->modelName; $assetmodel->use_image = ($assetmodel->image) ? url('/').'/uploads/models/'.$assetmodel->image : null; } diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index aa485399d8..71af09422e 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -169,6 +169,32 @@ class AssetModel extends SnipeModel } + /** + * Query builder scope to search on text, including catgeory and manufacturer name + * + * @param Illuminate\Database\Query\Builder $query Query builder instance + * @param text $search Search term + * + * @return Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeSearchByManufacturerOrCat($query, $search) + { + + return $query->where('models.name', 'LIKE', "%$search%") + ->orWhere('model_number', 'LIKE', "%$search%") + ->orWhere(function ($query) use ($search) { + $query->whereHas('category', function ($query) use ($search) { + $query->where('categories.name', 'LIKE', '%'.$search.'%'); + }); + }) + ->orWhere(function ($query) use ($search) { + $query->whereHas('manufacturer', function ($query) use ($search) { + $query->where('manufacturers.name', 'LIKE', '%'.$search.'%'); + }); + }); + + } + /** * Query builder scope to order on manufacturer * @@ -182,5 +208,18 @@ class AssetModel extends SnipeModel return $query->leftJoin('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order); } + /** + * Query builder scope to order on category name + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderCategory($query, $order) + { + return $query->leftJoin('categories', 'models.category_id', '=', 'categories.id')->orderBy('categories.name', $order); + } + } diff --git a/public/js/build/all.js b/public/js/build/all.js index b35517b1c6..1a69e18fa9 100644 Binary files a/public/js/build/all.js and b/public/js/build/all.js differ diff --git a/public/js/dist/all.js b/public/js/dist/all.js index b35517b1c6..1a69e18fa9 100644 Binary files a/public/js/dist/all.js and b/public/js/dist/all.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 944cf7fb71..a4e607fcec 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -8,7 +8,7 @@ "/css/app.css.map": "/css/app.css.map?id=bdbe05e6ecd70ccfac72", "/css/overrides.css.map": "/css/overrides.css.map?id=898c91d4a425b01b589b", "/css/dist/all.css": "/css/dist/all.css?id=51e5995cec7ce583f5dd", - "/js/dist/all.js": "/js/dist/all.js?id=7b52ead3a55086ea1f8d", + "/js/dist/all.js": "/js/dist/all.js?id=88f08e0103b14f7949b3", "/css/build/all.css": "/css/build/all.css?id=51e5995cec7ce583f5dd", - "/js/build/all.js": "/js/build/all.js?id=7b52ead3a55086ea1f8d" + "/js/build/all.js": "/js/build/all.js?id=88f08e0103b14f7949b3" } \ No newline at end of file diff --git a/resources/assets/js/snipeit.js b/resources/assets/js/snipeit.js index d58d7a704e..f826be9827 100755 --- a/resources/assets/js/snipeit.js +++ b/resources/assets/js/snipeit.js @@ -241,9 +241,9 @@ $(document).ready(function () { var markup = "