Laravel 5 - 如何从使用 Route::controllers() 定义的路由中获取操作名称(用于在具有 route() 函数的模板中获取 url)?
Laravel 5 - how to get action names (for getting urls in templates with route() function) from routes defined using Route::controllers()?
我是 Laravel 的新手,我正在尝试使用 named routes, but I can't find any documentation pertaining to this scenario.. I want to generate URLs to the default authentication based routes that Laravel ships with, but coming from Silex I really dislike the idea of generating URLs using the url
function and specifying the path.. I like using a bound name that I give the route (here are some examples from silex) 生成 URL,有什么方法可以指定名称(或者是否有我可以使用的动态名称)为使用 Route::controller
或 Route::controllers
定义的路由生成 URL?例如,我将在我的模板中将什么传递给 route
以生成 logout
url?
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
如果我想这样做,我是否只需要深入了解特征并手动指定每个控制器方法?
您可以在 controller
:
的第三个参数中将您的路线名称设置为数组
Route::controller('auth', 'Auth\AuthController', [
'getLogin' => 'auth.login',
]);
无法批量分配它们。
您可以在使用时为不同的控制器操作设置名称Route::controller
:
Route::controller('auth', 'Auth\AuthController', [
'getLogin' => 'auth.login',
'getLogout' => 'auth.logout',
// and so on
]);
不过,您也可以使用 action()
帮助程序代替 route()
或 url()
。它让您指定要生成 URL 的控制器和方法:
action('Auth\AuthController@getLogin')
我是 Laravel 的新手,我正在尝试使用 named routes, but I can't find any documentation pertaining to this scenario.. I want to generate URLs to the default authentication based routes that Laravel ships with, but coming from Silex I really dislike the idea of generating URLs using the url
function and specifying the path.. I like using a bound name that I give the route (here are some examples from silex) 生成 URL,有什么方法可以指定名称(或者是否有我可以使用的动态名称)为使用 Route::controller
或 Route::controllers
定义的路由生成 URL?例如,我将在我的模板中将什么传递给 route
以生成 logout
url?
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
如果我想这样做,我是否只需要深入了解特征并手动指定每个控制器方法?
您可以在 controller
:
Route::controller('auth', 'Auth\AuthController', [
'getLogin' => 'auth.login',
]);
无法批量分配它们。
您可以在使用时为不同的控制器操作设置名称Route::controller
:
Route::controller('auth', 'Auth\AuthController', [
'getLogin' => 'auth.login',
'getLogout' => 'auth.logout',
// and so on
]);
不过,您也可以使用 action()
帮助程序代替 route()
或 url()
。它让您指定要生成 URL 的控制器和方法:
action('Auth\AuthController@getLogin')