route() helper returns invalid URL for named route with two optional params
I have two routes. First is main route for home page (url: /), second is for test and have two optional params - id and name. I want to make redirect from home page to named route "test", but route() helper returns invalid URL
This is my code:
/**
* @var Laravel\Lumen\Routing\Router $router
*/
$router->get('/', function () {
return route('test');
// return redirect()->route('test');
});
$router->get('/test[/{id}[/{name}]]', [
'as' => 'test', function ($id = 0, $name = '') {
if ($name) {
return "Name: $name (ID: $id)";
}
if ($id) {
return "ID: $id";
}
return 'Need an id or name!';
}
]);
@omda and I just don't know why route() returns invalid URL with brackets like in route declaration. I think in my case URL that returned by route() must be like this example.com/test