diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 84fd58c544..a0743c16c2 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -141,18 +141,27 @@ class AccessoriesController extends Controller return ['total' => 0, 'rows' => []]; } + $offset = request('offset', 0); + $limit = request('limit', 50); + $accessory->lastCheckoutArray = $accessory->lastCheckout->toArray(); $accessory_users = $accessory->users; - + $total = $accessory_users->count(); + + if($total < $offset){ + $offset = 0; + } + + $accessory_users = $accessory->users()->skip($offset)->take($limit)->get(); + if ($request->filled('search')) { $accessory_users = $accessory->users() ->where('first_name', 'like', '%'.$request->input('search').'%') ->orWhere('last_name', 'like', '%'.$request->input('search').'%') ->get(); + $total = $accessory_users->count(); } - - $total = $accessory_users->count(); - + return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $accessory_users, $total); } diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 30a0f5931f..46ed622e01 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -231,10 +231,6 @@ class LicensesController extends Controller $offset = request('offset', 0); $limit = request('limit', 50); - if($seats->count() < $offset){ - $offset = 0; - } - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $total = $seats->count();