Remove old redundant code in LicensesController, added an offset to AccessoriesController for pagination to work correctly (#6847)

This commit is contained in:
Ivan Nieto 2019-04-02 11:13:58 -06:00 committed by snipe
parent b779e274cc
commit b1f96448af
2 changed files with 13 additions and 8 deletions

View file

@ -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);
}

View file

@ -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();