From 021c4f259857227f32508b4e9a53983bd241b143 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 4 Dec 2024 22:15:03 +0000 Subject: [PATCH] Added assets endpoint Signed-off-by: snipe --- app/Http/Controllers/Api/LocationsController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 52ef4ab93..f4f788d56 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -232,7 +232,17 @@ class LocationsController extends Controller return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors())); } + public function assets(Request $request, Location $location) : JsonResponse | array + { + $this->authorize('view', Asset::class); + $this->authorize('view', $location); + $assets = Asset::where('location_id', '=', $location->id)->with('model', 'model.category', 'assetstatus', 'location', 'company', 'defaultLoc'); + $assets = $assets->get(); + return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request); + } + + public function assignedAssets(Request $request, Location $location) : JsonResponse | array { $this->authorize('view', Asset::class); $this->authorize('view', $location);