Reputation: 125
I have the route:
Route::get('/inventoryFromCat', 'infoController@getInventory');
And I have the method:
$inventory = DB::table('inventory')->where('category', $request->categoryId)->paginate(10);
$inventory->setPath('inventoryFromCat');
First page is okay, but the following is empty. For example, first page:
Second page:
Url on first page:
http://localhost/inventory.site/public/inventoryFromCat?editCatName=&categoryId=1&_token=19DRwV4hv7RZUExqloz3fy3TAn9CSMad8BT2ktFq
Url on second page:
http://localhost/inventory.site/public/inventoryFromCat?page=2
Full function:
public function getInventory(Request $request)
{
if ($request->searchInput) {
$inventory = DB::table('inventory')->where('id', $request->searchInput)->get();
return view('admin/singleInventory', compact("inventory"));
} else if ($request->categoryId) {
$inventory = DB::table('inventory')->where('category', $request->categoryId)->paginate(10);
$inventory->setPath('inventoryFromCat');
$category = $this->getCategory($request->categoryId, false);
return view("inventoryFromCategory", compact("inventory", "category"));
} else if ($request->invId) {
$inventory = DB::table('inventory')->where('id', $request->invId)->get();
return view("singleInventory", compact("inventory", "barcode"))->render();
} else if ($request->invIdForEdit) {
$category = $this->getCategory(null);
$currentCat = $this->getCategory($request->invCat);
$editInventory = DB::table('inventory')->where('id', $request->invIdForEdit)->get();
return view("editInventory", compact("editInventory", "category", "currentCat"))->render();
}
}
Can somebody help me?
Upvotes: 0
Views: 69
Reputation: 2590
When calling ->links()
in your view, you need to add those additional query string parameters (editCatName
and categoryId
?). See 'Appending To Pagination Links' in the docs - https://laravel.com/docs/5.6/pagination#displaying-pagination-results
It should look something like:
$inventory->appends(['categoryId' => $categoryId, 'editCatName' => $editCatName])->links()
Obviously check that $categoryId
and $editCatName
are passed to your view as well.
Upvotes: 1