p1mps's avatar
Level 1

Lumen Optional Route Parameters

I tried to get a route with optional parameters following the FastRoute syntax but I didn't have succes. Is this correct?

$app->get('/{route}/{method}/{parameters?}/{cookie?}', function ($route, $method, $parameters, $cookie) use ($app) {
}

Where parameters and cookie should be optional. If it's not can you tell me how to write it?

I have the feeling that this is not possible to have since in the documentation there's no mention to optional parameters but I wanted to double check :)

Thanks

0 likes
2 replies
p1mps's avatar
Level 1

Ok it works if I do so:

$app->get('/{route}/{method}[/{parameters}/{cookie}]', function ($route, $method, $parameters = NULL, $cookie = NULL) use ($app) {

Setting the closure parameters as NULL. Thank you for the answer!

Please or to participate in this conversation.