From 8bc9688d719d84a657cb7455dc88604be291fca2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Mar 2024 16:04:00 +0000 Subject: [PATCH] =?UTF-8?q?Added=20ability=20to=20filter=20on=20category?= =?UTF-8?q?=20ID=20and=20model=20ID=20from=20user=E2=80=99s=20asset=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index e9551d51a8..5ef45ee4d9 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -560,7 +560,26 @@ class UsersController extends Controller { $this->authorize('view', User::class); $this->authorize('view', Asset::class); - $assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model')->get(); + $assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model'); + + + // Filter on category ID + if ($request->filled('category_id')) { + $assets = $assets->InCategory($request->input('category_id')); + } + + + // Filter on model ID + if ($request->filled('model_id')) { + + $model_ids = $request->input('model_id'); + if (!is_array($model_ids)) { + $model_ids = array($model_ids); + } + $assets = $assets->InModelList($model_ids); + } + + $assets = $assets->get(); return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request); }