Creating URLs using the route action/handler

By @samuel · 2021-11-01 18:57

Creating URLs using the route action/handler

  • By @ralphjsmit · 2021-11-09 09:05

    I see that you can also use the shorthand action() function, nice.

    Any idea how this sort of URL looks like? Does it go to the routes file and check whether there's a route that is connected to the same controller?

    • By @samuel · 2021-11-09 13:11

      The URL is the same as the one that route names would generate:

      route('post.create'); // /posts/create
      url()->action([PostController::class, 'create']); // /posts/create
      
      • By @ralphjsmit · 2021-11-09 14:34

        Thanks Samuel!

        (I'm replying here, because Upvoting or Replying on one of the below items is not working for me, because I got a few 500 Livewire errors. I'm using the latest Safari.)

      • By @ralphjsmit · 2021-11-09 13:27

        Okay! So with this routes file:

        Route::get('/user', [PostController::class, 'index'])->name('prefix.user.index');
        

        This:

        route('prefix.user.index'); 
        

        is giving the same as this:

        url()->action([PostController::class, 'index']);
        

        ?

        • By @samuel · 2021-11-09 13:49

          Yeah, should be the same thing. You can test that in tinker to check.