From 4b2093b485fb55b93186b339b82fef2f022c27d8 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 21 Sep 2018 15:51:26 -0700 Subject: [PATCH] Added counts to location show() API method --- .../Controllers/Api/LocationsController.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 2ec5ecc3aa..452b5b73b9 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -106,7 +106,26 @@ class LocationsController extends Controller public function show($id) { $this->authorize('view', Location::class); - $location = Location::findOrFail($id); + $location = Location::with('parent', 'manager', 'childLocations') + ->select([ + 'locations.id', + 'locations.name', + 'locations.address', + 'locations.address2', + 'locations.city', + 'locations.state', + 'locations.zip', + 'locations.country', + 'locations.parent_id', + 'locations.manager_id', + 'locations.created_at', + 'locations.updated_at', + 'locations.image', + 'locations.currency' + ]) + ->withCount('assignedAssets') + ->withCount('assets') + ->withCount('users')->findOrFail($id); return (new LocationsTransformer)->transformLocation($location); }