无需某些方法即可在Laravel中创建资源路由 [英] Create resource route in Laravel without certain methods
问题描述
我正在使用一些AJAX构建我的Web应用程序,但没有使用资源控制器中的所有方法。是否可以使用 php artisan
创建没有某些方法的资源控制器?谢谢
I'm building my web application with some AJAX and I'm not using all the methods from a resource controller. Is it possible to create a resource controller without some methods with php artisan
? Thanks
推荐答案
您可以通过将参数传递给路由定义来指定要为资源包括哪些路由:
You may specify which routes you would like to be included for the resource by passing an argument to the route definition like so:
Route::resource('photo', 'PhotoController', ['only' => [
'index', 'show'
]]);
运行 artisan
生成器时,仍然可以获得所有方法,但是您可以删除它们。如果要创建仅创建某些方法的自定义命令,则仍然需要记住 Route :: resource
默认情况下需要所有资源路由。
When you run the artisan
generator you will still get all the methods, but you can just delete them. If you were to create a custom command to only create certain methods, you would still need to keep in mind that Route::resource
expects all resource routes by default.
这篇关于无需某些方法即可在Laravel中创建资源路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!