Are you not passing "pageStart" with your filters?
I mean, if you are at page 10 and search, maybe after filtering you will have less then 10 pages. When search you nessd to clear the pageStart.
Pagination is currently working on my index page, but when you search for an Item, and return results with pagination, the pagination breaks.
postSearch Method looks like this:
public function postSearchItems(ItemSearchRequest $request, $limit = 5)
{
if (\Request::has('itemID')) {
// Since the item search select can only accommodate the ItemID but we want to be able to do a like search
// on the ItemName, we still use the ItemID to get the item name and then do a search on it.
$itemQuery = Item::where('ItemName', 'LIKE', '%' . Item::where('ItemID',\Request::get('itemID'))->first()->ItemName . '%');
}
if (\Request::has('itemPOSID')) {
$itemQuery = \Request::has('itemID') ? $itemQuery->where('POSID', \Request::get('itemPOSID')) :
Item::where('POSID', \Request::get('itemPOSID'));
}
$filterStatus = \Request::get('itemStatus');
$filterIsCombo = \Request::get('isComboItem');
$filterIsModifier = \Request::get('isModifier');
if ($filterStatus != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('ItemActive', $filterStatus);
}
if ($filterIsCombo != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('IsComboItem', $filterIsCombo);
}
if ($filterIsModifier != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('isModifier', $filterIsModifier);
}
return view("admin::menus.items.itemsIndex", [
'items' => $itemQuery->where('RestaurantID',
$this->restaurantService->restaurant->RestaurantID)->with('categories')->paginate($limit),
'mainMenu' => 'Manage Menus',
'subMenu' => 'Items'
]);
}
tried to set up manual pagination and i get a trying to get a undefined property error in the blade.
$pageStart = \Request::get('page', 1);
$perPage = 10;
$offSet = ($pageStart * $perPage) - $perPage;
$itemsForCurrentPage = array_slice($itemQuery, $offSet, $perPage, true);
$items = new LengthAwarePaginator($itemsForCurrentPage, count($itemQuery), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
array_slice breaks with $itemQuery being an object so i can add toArray() thats when the undefined property hits.
Try this, have refactored it a bit. appends() works on paginator and not collection
public function getSearchItems(ItemSearchRequest $request, $limit = 5)
{
$filter= [];
if (\Request::has('itemID')) {
$filter ['itemID']= \Request::get('itemID');
// Since the item search select can only accommodate the ItemID but we want to be able to do a like search
// on the ItemName, we still use the ItemID to get the item name and then do a search on it.
$itemQuery = Item::where('ItemName', 'LIKE', '%' . Item::where('ItemID',\Request::get('itemID'))->first()->ItemName . '%');
}
if (\Request::has('itemPOSID')) {
$filter ['itemPOSID']= \Request::get('itemPOSID');
$itemQuery = \Request::has('itemID') ? $itemQuery->where('POSID', \Request::get('itemPOSID')) :
Item::where('POSID', \Request::get('itemPOSID'));
}
if (\Request::has('itemStatus')) {
$filter['itemStatus'] = \Request::get('itemStatus');
if ($filter['itemStatus'] != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('ItemActive', $filter['itemStatus']);
}
}
if (\Request::has('isComboItem')) {
$filter['isComboItem'] = \Request::get('isComboItem');
if ($filter['isComboItem'] != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('IsComboItem', $filter['isComboItem']);
}
}
if (\Request::has('isModifier')) {
$filter['isModifier'] = \Request::get('isModifier');
if ($filter['isModifier'] != static::SHOW_ALL) {
$itemQuery = $itemQuery->where('ItemActive', $filter['isModifier']);
}
}
$items = $itemQuery->where('RestaurantID',
$this->restaurantService->restaurant->RestaurantID)->with('categories')->paginate($limit);
$items->appends($filter);
return view("admin::menus.items.itemsIndex", [
'items' => $items,
'mainMenu' => 'Manage Menus',
'subMenu' => 'Items'
]);
}
Please or to participate in this conversation.