如何命名我的 Route::resource
以便稍后在 Laravel 5.5 中调用它?
这有效
路线::get('newclientTAB', 'NewClientControllerTAB@index')->name('newclientTAB');
这不
Route::resource('articles','ArticleController')->name('articles');
最佳答案
如果您使用:
Route::resource('articles','ArticleController')
Laravel 会自动为你的路线设置名称。
您可以运行:
php artisan route:list
去看他们。
遗嘱的名称:
- 文章索引
- 文章.store
- 文章.create
- 文章.show
- 文章.更新
- 文章.destroy
- 文章.编辑
但是,如果您想使用自定义名称前缀,您可以这样设置:
Route::resource('articles','ArticleController', ['names' => 'xyz'])
然后您的路线将具有名称 xyz.index
、xyz.store
等
如果您想更进一步,您还可以设置个人名称,例如:
Route::resource('articles','ArticleController', ['names' => ['create' => 'foo','update' => 'bar']])
这样你就可以只为某些路由设置名称,这样你就会得到foo
、bar
和articles.index
、articles。显示
等等
关于Laravel 5.5 命名 Route::resource 供以后使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47906361/