Added counts to API
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
63a05c89a7
commit
4839181beb
1 changed files with 15 additions and 2 deletions
|
@ -20,9 +20,22 @@ class DepreciationsController extends Controller
|
||||||
public function index(Request $request) : JsonResponse | array
|
public function index(Request $request) : JsonResponse | array
|
||||||
{
|
{
|
||||||
$this->authorize('view', Depreciation::class);
|
$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')) {
|
if ($request->filled('search')) {
|
||||||
$depreciations = $depreciations->TextSearch($request->input('search'));
|
$depreciations = $depreciations->TextSearch($request->input('search'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue