Join my Laravel for REST API's course on Udemy 👀

Redirect to a different route in Laravel

June 29, 2022  ‐ 1 min read

Redirecting to a different route is a common practice after you have submitted a form successfully. In Laravel we can achieve this by returning with the redirect() helper in our controllers.

As a first argument to the redirect() function we can pass the URI to redirect to.

<?php

public function store(Request $request)
{
    return redirect('/posts');
}

If you are not redirecting to an external site it is probably neater to use named routes instead. Which would look like the following.

<?php

public function store(Request $request)
{
    return redirect()->route('posts.index');
}