How do I give route name to a closure route in Lumen?

Viewed 2348

Hi I have the following Lumen Route

$router->get('/end', function (\Illuminate\Http\Request $request) use ($router) {
    $controller = $router->app->make('App\Http\Controllers\Legacy\EndLegacyController');
    return $controller->index($request);
});

I am trying to give it a route name so that I can use redirect to redirect to this route like redirect()->route('name_of_route')

so far I have tried

})->namedRoute['end'] = '/end'; // No Effect
})->name('end') //Undefined function

but it didn't work here's a list of present routes enter image description here

Edit Because of my certain requirement, I can't use ['as' => 'end', 'uses'=> 'ControllerName@Action']

1 Answers

you can use the following syntax: $router->get('/end', ['as'=>'name_here', function()]);

Related