0

I have a list of routes, some are using parameters and everything is working correctly. My problem happen when I try to constrain the parameter (to check the it is valid before executing my controller).

Following the documentation I did it this way :

    $router->group(['middleware' => 'auth:api'], function () use ($router) {
    $router->get('/user/{userId:[a-z0-9]+}', 'UserController@userByUserIdGet');
});

But all I receive is a NotFoundHttpException meaning that it doesn't match my route.

I can't see where my mistake is. Any idea?

Thank you.

Fabrice Lefloch
  • 409
  • 4
  • 16

2 Answers2

0

The error you recieve, if your route doensn't exists is a MethodNotAllowedHttpException - your code and the regex for your route do work correctly, so I am assuming, that your error could have an other reason.

Maybe you should check this: NotFoundHttpException with Lumen

Tries
  • 3
  • 5
  • Hello, thank you for answering my question, but unfortunately this doesn't solve my problem. The MethodNotAllowedHttpException is only thrown if for example I call a post method where I only have a GET route. If I fallback to my route without the regex it's working correctly. – Fabrice Lefloch Sep 25 '19 at 13:08
0

OK stupid error from my side. I'm passing UUID as userID parameter... AND they have a dash in them. So my regex should be this one

$router->group(['middleware' => 'auth:api'], function () use ($router) {
   $router->get('/user/{userId:[a-z0-9\-]+}', 'UserController@userByUserIdGet');

});

Fabrice Lefloch
  • 409
  • 4
  • 16