Level 102
You need to ensure that you send the search term on all pagination buttons as well, so they remain in the url
public function search(Request $request) { $search = $request->input('search'); $category = $request->input('category');
$results=DB::table('products')
->where('name', 'like', "%{$search}%")
->select('products.*')
->groupBy('name')
->where('status','=','on')
->paginate(12);
$products = $results;
$type=$request->type;
return view('site.products',compact('products','type'));
}
This is a search function and I return that back to products page but when I do that the pagination works as I search something so there comes pagination on the first page but when I go to page 2 then it does not take me to the search's next page rather takes me to the seconf page of overall products page
I assume you have a GET request for searching; you can append the current search term to the query string:
$results=DB::table('products')
->where('name', 'like', "%{$search}%")
->select('products.*')
->groupBy('name')
->where('status','=','on')
->paginate(12)
->withQueryString();
Please or to participate in this conversation.