How can you create wildcard routes on Lumen?

  fastroute, laravel, lumen, php, routes

Let’s say I have a controller called TeamsController. Controller has following method, that returns all teams user has access to.

public function findAll(Request $request): JsonResponse
{
  //...
}

Then I have bunch of other controllers with the same method. I would like to create a single route, that would work for all controllers, so I would not need to add a line for each controller every time I create a new controller.

I am unable to catch the controller name from URI. This is what I have tried.

$router->group(['middleware' => 'jwt.auth'], function () use ($router) {
    // This works
    //$router->get('teams', '[email protected]');
    
    // This just returns [email protected] string as a response
    $router->get('{resource}', function ($resource) {
        return ucfirst($resource) . '[email protected]';
    });
});

Source: Laravel

Leave a Reply