search

Home  >  Q&A  >  body text

Understand what is the meaning of "to_route('route_name')" method 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 to find an explanation in the Laravel documentation but didn't find any useful information.

P粉494151941P粉494151941455 days ago585

reply all(1)I'll reply

  • P粉743288436

    P粉7432884362023-09-16 14:13:31

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

    You can also view 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's actually a redirect just like you posted.

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

    reply
    0
  • Cancelreply