jcalonso
2530
10
Lumen

Lumen - Route with optional parameters

Posted 4 years ago by jcalonso

Hello,

I'm starting new app with Lumen and I'm trying to create a route with optional parameters like this:

$app->get('user/{param?}',[
    'as'   => 'user',
    'uses' => 'App\Http\Controllers\UserController@get'
]);

And the controller:

public function get($param = null)
    {
    ...
    }

If I hit the url http://myApp.dev/user/ I get a 404

if I hit http://myApp.dev/user/something It get routed but the $param variable is null.

I was looking at nikic/FastRouter (lumen router) and I couldn't find any support for optional parameters.

Am I missing something, or there is no support for optional parameters?

Thanks!

Please sign in or create an account to participate in this conversation.