Master Laravel Redirect: Quick Reference Guide with Code Examples
This concise Laravel Redirect cheat sheet explains the helper's purpose and provides clear code snippets for common redirection scenarios such as simple URL redirects, passing data, redirecting back, using named routes, controller actions, and handling intended destinations.
Redirect is a helper class in Laravel that simplifies route redirection.
Basic Redirect
return Redirect::to('foo/bar');Redirect with Data
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 Back to Previous Request
// Redirect back to the previous request
return Redirect::back();Redirect Using Named Routes
// Simple named route
return Redirect::route('foobar');
// Named route with parameters
return Redirect::route('foobar', ['value']);
// Named route with key‑value parameters
return Redirect::route('foobar', ['key' => 'value']);Redirect to Controller Actions
// Redirect to a controller action
return Redirect::action('FooController@index');
// Redirect with parameters
return Redirect::action('FooController@baz', ['value']);
// Redirect with key‑value parameters
return Redirect::action('FooController@baz', ['key' => 'value']);Redirect to Intended Destination
// Redirect to the intended URL, falling back to a default
return Redirect::intended('foo/bar');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.
