I am fetching records via ajax with search parameters and want to have pagination also. It works fine if I use it with the same function which loads view, for example
function viewOrder(Request $request){
$data = products::where('categoryId', 1)->paginate(1);
if ($request->ajax()){
return view('store.showAjax')->with('data',$data);
}
return view('store.show')->with('data',$data);
}
But my need is like this
function viewOrder(){
return view('store.show');
}
function searchOrder(Request $request){
$data = products::where('categoryId', 1)->paginate(1);
return view('store.show')->with('data',$data);
}
In this way It creates pagination but when I click on page link it load store.show view twice in the same html page. How can I achieve correct pagination this way? Doing everything in viewOrder() function looks messy.