Skip to content

Commit

Permalink
Merge pull request #14509 from snipe/feature/sc-25173/filter_assigned…
Browse files Browse the repository at this point in the history
…_user_assets_by_category_id

Added ability to filter in user's assigned assets by category ID and model ID
  • Loading branch information
snipe committed Mar 27, 2024
2 parents ae403da + 8bc9688 commit befa442
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,26 @@ public function assets(Request $request, $id)
{
$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);
}
Expand Down

0 comments on commit befa442

Please sign in to comment.