[英]Get route by name - Laravel 5.4
I want dynamic uri for Auth routes depending on the language. 我想根据语言来使用Auth路由的动态uri。
Is there a way to get a route result by name? 是否可以通过名称获取路线结果?
For example with the Auth routes: 例如,使用Auth路由:
Route::get(route('login'));
Thank you for your ideas... 谢谢你的想法...
I normally use them as such: 我通常这样使用它们:
//Routes
Route::post('/login',[
'uses'=>'HomeController@login',
'as'=>'login'
]);
// Calling them in blade
{{route('login')}} -> xxxxx/login
You can still get more information on the best documentation of the world: https://laravel.com/docs/5.4/routing#named-routes 您仍然可以获得有关世界上最好的文档的更多信息: https : //laravel.com/docs/5.4/routing#named-routes
If you want the url for the named route, for example to use it in your views, you should just use route('routename')
(ofcourse you should replace route_name
with the name of your route). 如果您想要命名路由的url,例如在视图中使用它,则应仅使用
route('routename')
(当然,您应将route_name
替换为路由名称)。 You do not need the Route::get
around that, the Route::get/post/put/patch/delete functions are for defining new routes, not to get the url for a route. 您不需要
Route::get
解决,Route :: get / post / put / patch / delete函数用于定义新路由,而不是获取路由的url。
Take a look at https://laravel.com/docs/5.4/routing#named-routes on how to create named routes and properly link to them. 看一下https://laravel.com/docs/5.4/routing#named-routes ,了解如何创建命名路由并正确链接到它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.