I have just started with Laravel and I am trying to make a search function with proper pagination. The function works for page one but on pag
I assume you want to change pages with urls like this search/1
, search/2
? First of all your route should be probably Route::post('search/{page?}')
.
I'm not sure if only this change will work, but if it does not, you have to resolve page like this
public function search(\Illuminate\Http\Request $request, $page = 1)
{
$q = $request->get('search');
\Illuminate\Pagination\Paginator::currentPageResolver(function () use ($page) {
return $page;
});
# going to next page is not working yet
$product = Product::where('naam', 'LIKE', '%' . $q . '%')
->orWhere('beschrijving', 'LIKE', '%' . $q . '%')
->paginate(6);
return view('pages.index', compact('product'));
}