如何给流明的封闭路线指定路线名称? [英] How do I give route name to a closure route in Lumen?

查看:58
本文介绍了如何给流明的封闭路线指定路线名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下流明路线

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

我正在尝试为其提供一个路由名称,以便我可以使用重定向来重定向到该路由,例如 redirect()-> route('name_of_route')

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

修改由于我的特定要求,我不能使用 ['as'=>'end','uses'=>'ControllerName @ Action']

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

推荐答案

,您可以使用以下语法: $ router-> get('/end',['as'=>'name_here',function()]);

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

这篇关于如何给流明的封闭路线指定路线名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆