Laravel API controller structure?

Which one has controller structure for api user?

Separate controller for interface and API for each version of api

/app/controllers/UsersController.php
/app/controllers/api/v1/ApiUsersController.php

or

Separate the controller for the interface and API and control the versions in the code

/app/controllers/UsersController.php
/app/controllers/api/ApiUsersController.php 

or

Use one controller, detect / api / call inside the router. Return html / json depending on the url.

/app/controllers/UsersController.php  
+3
source share
2 answers

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

, , . , , .

, , . API , , .

, , ApiUserController, UserController, namespacing. , \UserController Api\V1\UserController .

+4

. 1- . 1 .

+1

Source: https://habr.com/ru/post/1675749/


All Articles