Redirect to a URL in Laravel 6, 7 & 8

To redirect to a URL in Laravel, use the built-in redirect() function. Pass the redirect path as the first argument like this:

 

return redirect('/home/dashboard');

 

Redirect to Previous Page

To redirect a user to the previous page, use the back() function like this:

 

return back();

 

If you need to redirect back with input data, use the withInput() function like this:

 

return back()->withInput();

 

Redirect to Named Routes

To redirect to a named route, use the route() function like this:

 

return redirect()->route('login');

 

If your route has parameters, pass them as an array in the second argument of the route() function like this:

 

return redirect()->route('profile', ['id' => 1]);

 

Redirect with Flashed Session Data

To redirect with flashed session data in Laravel, use the with() function like this:

 

return redirect('/dashboard')->with('status', 'Profile updated!');