From 4839181beb926bbed2ef357078ba0892340384c2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Aug 2024 12:40:01 +0100 Subject: [PATCH] Added counts to API Signed-off-by: snipe --- .../Controllers/Api/DepreciationsController.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 0209eae392..72e0f3a14a 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -20,9 +20,22 @@ class DepreciationsController extends Controller public function index(Request $request) : JsonResponse | array { $this->authorize('view', Depreciation::class); - $allowed_columns = ['id','name','months','depreciation_min', 'depreciation_type','created_at']; + $allowed_columns = [ + 'id', + 'name', + 'months', + 'depreciation_min', + 'depreciation_type', + 'created_at', + 'assets_count', + 'models_count', + 'licenses_count', + ]; - $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at'); + $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at') + ->withCount('assets as assets_count') + ->withCount('models as models_count') + ->withCount('licenses as licenses_count'); if ($request->filled('search')) { $depreciations = $depreciations->TextSearch($request->input('search'));