You have to append parameters to query string, example:
In controller
$params = array('psch' => $dogsearch, 'aval' => $aval);
Pass $params to view also.
view
{{ $dogs->appends($params)->links() }}
Scroll to Appending To Pagination Links
I have an issue after applying filters on my records. Essentially, once the filtering process is done the pagination links break and try to point to a page that doesn't exist.
I'll try to give you the code step by step, let's start with the route:
Route::post('/filter-leads', 'FiltersController@leadsFilter');
That gets sent all the filter criteria by AJAX. Next up is the controller:
public function leadsFilter(Request $request) {
//return response()->json($request); //value checker pre-validation
$val = $request->validate([
'startDate' => 'nullable|date',
'endDate' => 'nullable|date',
'leadTypes.*' => 'nullable|string',
]);
//return response()->json($val); //value checker post-validation
//default static variables
$company = Company::where('id', auth()->user()->company_id)->first();
$status = LeadStatusOption::where('company_id', auth()->user()->company_id)->get();
$query = Lead::query()->where('company_id', $company->id);
//if catchers and query scalers
if($request->filled(['startDate', 'endDate'])) {
$startDate = Carbon::createFromFormat('Y-m-d', $val['startDate'])->format('d/m/Y'); //carbon usage needed due to the format the model is expecting, this then gets converted by the scope
$endDate = Carbon::createFromFormat('Y-m-d', $val['endDate'])->format('d/m/Y');
$query = $query->StartDate($startDate)->EndDate($endDate);
}
else if ($request->filled('startDate')){
$startDate = Carbon::createFromFormat('Y-m-d', $val['startDate'])->format('d/m/Y');
$query = $query->StartDate($startDate);
}
else if ($request->filled('endDate')){
$endDate = Carbon::createFromFormat('Y-m-d', $val['endDate'])->format('d/m/Y');
$query = $query->EndDate($endDate);
}
if($request->filled('leadTypes')) {
$query = $query->LeadTypes($val['leadTypes']);
}
//final query builder
$leads = $query->paginate(15);
return view('partials.leadTable')
->with([
'leads' => $leads,
'company' => $company,
'status' => $status,
]);
}
After that I just use the {{$leads->links()}} on the bottom of my page. First of all, this is what the url looks like on the base page with working pagination: http://demo:8888/test-module/leads?page=1
Then after filtering this is what it gives me: http://demo:8888/test-module/filter-leads?page=2 with the following error message:
InvalidArgumentException View [show] not found. http://demo:8888/test-module/filter-leads?page=2 Hide solutions show was not found. Did you mean home?
I'd appreciate any help with this!
Thank you in advance!
Please or to participate in this conversation.