Support the ongoing development of Laravel.io →
Requests Input

Hi,

i'm not sure how to solve this:

  1. I list all customers (with sorting options via URL query ?sort=...&city...)
  2. I click on "Create new customer"
  3. I save the new customer
  4. I want to redirect to step 1 with a) the same sorting settings AND with the new user (of course only displayed if he fits into the search request).

Inside MyController():

public function saveCustomer()
{

// save data into db

return Redirect::action('MyController@listCustomers');

}

Okay this just redirects to "List all customers" without any sorting :(

Instead of this i tried

return Redirect::back();

but this redirects only to the last page (the new-customer-form).

So i need something like javascript history go back(-2) but with a refresh of that url.

Maybe put the referer into a hidden field inside the form and send it to the saveCustomers controller?

return Redirect::to(Input::get('referer'));

Any other ideas?

Thanks, Sharping

Last updated 2 years ago.
0

just type this

echo '<script type="text/javascript">'
			   , 'history.go(-2);'
			   , '</script>';
Last updated 2 years ago.
0

I would not rely on JavaScript code as JS may be disabled in a browser. Instead, at step 2 I would put:

Session::flash('url',Request::server('HTTP_REFERER'));  

and then at step 4 I would redirect to the URL which is saved in the session variable:

return Redirect::to(Session::get('url'));  
Last updated 2 years ago.
0

sayasuhendra said:

just type this

echo '<script type="text/javascript">'
  		   , 'history.go(-2);'
  		   , '</script>';

Your solution will redirect to second last page but can not load new customer.

Alkimisti said:

I would not rely on JavaScript code as JS may be disabled in a browser. Instead, at step 2 I would put:

Session::flash('url',Request::server('HTTP_REFERER'));  

and then at step 4 I would redirect to the URL which is saved in the session variable:

return Redirect::to(Session::get('url'));  

This solution is mean When you in step one, you flash session url now and you can get session url after submit new customer

Last updated 2 years ago.
0

Flash url in YourController@index

Session::flash('backUrl', Request::fullUrl());

Keep the sub session key in YourController@create and YourController@store

if (Session::has('backUrl')) {
    Session::keep('backUrl');
}

Consume the session value in YourController@store or any subsequent views

// YourController@store
return ($url = Session::get('backUrl')) 
    ? Redirect::to($url) 
    : Redirect::route('any.named.route');

// or any views
@if ($url = Session::get('backUrl'))
    <a href="$url">Back to List</a>
@endif
Last updated 10 years ago.
0

Step 1 uses get tokens. Simply save the full URL in a session variable and use it to redirect in step 4. No need to over think it.

0

appkr said:

Flash url in YourController@index

Session::flash('backUrl', Request::fullUrl());

Keep the sub session key in YourController@create and YourController@store

if (Session::has('backUrl')) {
   Session::keep('backUrl');
}

Consume the session value in YourController@store or any subsequent views

// YourController@store
return ($url = Session::get('backUrl')) 
   ? Redirect::to($url) 
   : Redirect::route('any.named.route');

// or any views
@if ($url = Session::get('backUrl'))
   <a href="$url">Back to List</a>
@endif

Your answer solve my problem. Thanks a bunch

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.