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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Laravel Redirect Cheat Sheet

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendWeb DevelopmentPHPLaravelSessionRedirect
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.