Search code examples
phplaravellaravel-routing

What does to_route('route_name') mean in Laravel?


I saw this in this tutorial:

return to_route('route_name');

Does to_route('route_name') mean the same as redirect()->route('route_name)?

I tried finding an explanation in the Laravel docs, but couldn't find it helpful.


Solution

  • As the documentation states, to_route does redirect, so it should be the same as redirect()->route('name').

    You can also check the official source code, I will copy-paste the code:

    function to_route($route, $parameters = [], $status = 302, $headers = [])
    {
        return redirect()->route($route, $parameters, $status, $headers);
    }
    

    So, you can see, it is literally a redirect as you posted.

    ALWAYS check the official source code, and you will (most of the time) understand and see what some code does