Create resource route in Laravel without certain methods

偶尔善良 提交于 2019-12-10 17:51:12

问题


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


回答1:


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'
]]);

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.




回答2:


If you check out the API docs about ControllerMakeCommand you will see that it has only one option. So it's not possible to generate a controller without certain methods with the command that's shipped with laravel.

https://laravel.com/api/5.2/Illuminate/Routing/Console/ControllerMakeCommand.html

However you can make a command yourself that will accept arguments and based on your arguments it will generate a controller with only specified method.

Laravel docs on how to create a custom command



来源:https://stackoverflow.com/questions/39038981/create-resource-route-in-laravel-without-certain-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!