How to redirect to another page in Laravel?


by terrence , in category: SEO , 9 months ago

How to redirect to another page in Laravel?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by priscilla.langworth , 9 months ago


To redirect to another page in Laravel, you can use the redirect() method provided by the Laravel framework.

Here's how you can redirect to another page in Laravel:

  1. Inside your controller method, use the redirect() method to create a redirect response:
return redirect('/another-page');

In the above example, we are redirecting to the '/another-page' URL. You can replace '/another-page' with the desired URL.

  1. To redirect to a specific route name, use the route() method instead:
return redirect()->route('');

Replace '' with the name of the desired route.

  1. You can also redirect back to the previous page by using the back() method:
return back();

  1. It's also possible to add flash messages to the redirect response by chaining the with() method. For example:
return redirect('/another-page')->with('message', 'Redirected Successfully');

In this case, the flash message with the key 'message' and value 'Redirected Successfully' will be available on the redirected page.

Be sure to return the redirect response from your controller method.