Laravel Redirect Cheat Sheet
This article provides a concise Laravel Redirect cheat sheet that explains how to use the framework's URL redirection helper with session storage, covering basic redirects, redirects with data, back navigation, named routes, controller actions, and intended redirects, accompanied by ready-to-use code examples.
Redirect is Laravel's URL redirection helper that also stores session data, offering a convenient encapsulated way to perform various types of redirects.
Common usage examples include simple redirects, redirects with flash data, redirects preserving input, error redirects, back navigation, named route redirects, controller action redirects, and intended redirects.
return Redirect::to('foo/bar');
return Redirect::to('foo/bar')->with('key', 'value');
return Redirect::to('foo/bar')->withInput(Input::get());
return Redirect::to('foo/bar')->withInput(Input::except('password'));
return Redirect::to('foo/bar')->withErrors($validator);
// Redirect to the previous request
return Redirect::back();
// Redirect to a named route
return Redirect::route('foobar');
return Redirect::route('foobar', array('value'));
return Redirect::route('foobar', array('key' => 'value'));
// Redirect to a controller action
return Redirect::action('FooController@index');
return Redirect::action('FooController@baz', array('value'));
return Redirect::action('FooController@baz', array('key' => 'value'));
// Redirect to intended URL, defaulting to foo/bar if none set
return Redirect::intended('foo/bar');Helping others helps yourself; technology shapes life, and knowledge changes destiny.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
