L
L
Leopandro2018-05-14 16:14:10
Laravel
Leopandro, 2018-05-14 16:14:10

What folder structure to make for laravel api?

In general, an api should handle requests from a website + mobile app.
there should be versioning of api, controllers, models - to handle events differently for each role and for each version of the api. What is the best way to do this? at the moment everything is simple for me - routing - each file for each version and folders of controllers and models are also located by version. But somehow it becomes more and more difficult to work on such a project, you often have to refactor everything that catches your eye. Do you have any example of an ideal project? You can link to the github or attach some course.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SteepZero, 2018-05-14
@SteepZero

I would pack everything related to a specific version of the API (models, Http, repositories, resources, etc.) into my namespace
Or even a package
For each version of the API, its own service provider that connects routing from a custom file (eg V2.0 subfolder in the routes folder) and everything else, views, if necessary, can also be loaded from a custom folder by specifying a namespace (eg v2.0::index)
Tests can also be packed by specifying suitecase in phpunit.xml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question