kay899's avatar

Jump back to previous Pagination page

Hi,

I use Pagination in my Backend. When I chose an item on let's say page 3 and edit this, then after saving, Laravel leads be back to the first page of the Pagination.

Is there any trick to get back on page 3 again?

Thanks kay899

0 likes
4 replies
socieboy's avatar

When you click edit then create a hidden field and store the previous page,

{!! Form::hidden('redirects_to', URL::previous()) !!}

Then on your controller when you process your data or form just do

Return redirect->url($request->only('redirect_to'));

nasirkhan's avatar

The following solution worked for me on Laravel 5.1.


{!! Form::hidden('redirects_to', URL::previous()) !!}

Return redirect($request->only('redirects_to'));

jlrdw's avatar

Not laravel example, but similar

$vurl = Session::get('areturn');
return Redirect::to($vurl);     ///////controller code

Where areturn is a session that has the uri with the pagination appends.

How do you do that:

view code

$areturn = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$haystack = $areturn;
$needle = '?';
$pos = strripos($haystack, $needle);
if ($pos === false) {
    $areturn = $areturn . "?psch=" . Session::get('dogsearch') . "&aval=" . Session::get('dogaval') . "&page=1";
    Session::put('areturn', $areturn);
} else {

    Session::put('areturn', $areturn);
}

Please or to participate in this conversation.