0

I have tried to use pagination with laravel and everything works fine until I navigate to another page, then the request doesn't preserve the previous query string and, as a result, the query doesn't work anymore.

This is the query in the controller:

$inputDate =$request->input('date') ;
$endDate = date('Y-m-d', strtotime($inputDate. ' + 7 days'));

$shifts = DB::table('driver_shifts')
    ->join('drivers','drivers.PermitNumber','=','driver_shifts.driver_badge_id')
    ->where ('driver_shifts.shift_start_time','>',$inputDate)
    ->where ('driver_shifts.shift_start_time','<',$endDate)
    ->orderby("vehicle_id")
    ->orderby("shift_start_time")
    ->paginate(20);

return view('reports.WeeklyTaxiShifts.WeeklyTaxiShifts', compact('shifts','inputDate'));

1 Answer 1

2

You can try to use:

$shifts = DB::table('driver_shifts')
    ->join('drivers','drivers.PermitNumber','=','driver_shifts.driver_badge_id')
    ->where ('driver_shifts.shift_start_time','>',$inputDate)
    ->where ('driver_shifts.shift_start_time','<',$endDate)
    ->orderby("vehicle_id")
    ->orderby("shift_start_time")
    ->paginate(20)
    // this line will put back the query string parameters on the generated links
    ->appends(request()->query());

That is also explained with a blade usage example in the documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.