diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 904ac80792..e38d5382fa 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -35,7 +35,8 @@ class AssetMaintenancesController extends Controller public function index(Request $request) { $this->authorize('view', Asset::class); - $maintenances = AssetMaintenance::with('asset', 'asset.model', 'asset.location', 'supplier', 'asset.company', 'admin'); + + $maintenances = AssetMaintenance::select('asset_maintenances.*')->with('asset', 'asset.model', 'asset.location', 'supplier', 'asset.company', 'admin'); if ($request->filled('search')) { $maintenances = $maintenances->TextSearch($request->input('search')); @@ -45,6 +46,15 @@ class AssetMaintenancesController extends Controller $maintenances->where('asset_id', '=', $request->input('asset_id')); } + if ($request->filled('supplier_id')) { + $maintenances->where('supplier_id', '=', $request->input('supplier_id')); + } + + if ($request->filled('asset_maintenance_type')) { + $maintenances->where('asset_maintenance_type', '=', $request->input('asset_maintenance_type')); + } + + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which // case we override with the actual count, so we should return 0 items. $offset = (($maintenances) && ($request->get('offset') > $maintenances->count())) ? $maintenances->count() : $request->get('offset', 0); @@ -64,6 +74,7 @@ class AssetMaintenancesController extends Controller 'asset_tag', 'asset_name', 'user_id', + 'supplier' ]; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; @@ -72,6 +83,9 @@ class AssetMaintenancesController extends Controller case 'user_id': $maintenances = $maintenances->OrderAdmin($order); break; + case 'supplier': + $maintenances = $maintenances->OrderBySupplier($order); + break; case 'asset_tag': $maintenances = $maintenances->OrderByTag($order); break;