Laravel API controller structure?

感情迁移 提交于 2019-12-04 10:00:53

Definitely the first option is the best out of the three, and the reasons are scalability and maintenance.

If you use only one controller, as proposed in the third method, you will end up soon with a messy class with thousands of lines. Not only this is not going to scale well, but it will be hard to work with for you and your teammates.

The second choice is better than the third one, but still not the best. It's a better practice to be supporting API versioning from the start, and it will keep your routes, files and namespaces more organized.

By the way, instead of naming it ApiUserController you can use UserController too, as long as you are namespacing properly. So, you could have \UserController and Api\V1\UserController existing together.

Personal opinion. I prefer 1st option. All in 1 app, and versioning via namespace.

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