0

I am implementing versioning in Laravel. Now my doubt is, where should I create the V1 subfolders within the various main folders? For example, is it okay for controllers (Controllers/Api/V1) but what about Models, Resources, Request, Services etc...?

1
  • 4
    If you plan to evolve your service over time and might need to keep backwards compatibility to legacy clients there's no reason a v1 route would strictly use a v1 model or request or resource. You can evolve the rest of your code and ensure v1 routes still appear and function the same to the API consumers without necessarily using legacy code. Alternatively you can ditch the idea of writing a separate v2 of things and instead evolve your code as you would normally do and serve the updated Laravel app as a new app from a subpath using host configuration on your webserver Commented Jan 28, 2023 at 20:35

1 Answer 1

1

There is a very well maintained package specifically for what you are trying to do, called Laravel Modules: https://github.com/nWidart/laravel-modules

You can accomplish subversions of the application inside of it, and everything like "Models, Resource, Routes, etc.." is packaged seperately from one module to another.

Modules/
  ├── Blog/
      ├── Config/
      ├── Console/
      ├── Database/
          ├── factories/
          ├── Migrations/
          ├── Seeders/
      ├── Entities/
      ├── Http/
          ├── Controllers/
          ├── Middleware/
          ├── Requests/
      ├── Providers/
          ├── PostsServiceProvider.php
          ├── RouteServiceProvider.php
      ├── Resources/
          ├── assets/
          ├── lang/
          ├── views/
      ├── Routes/
          ├── api.php
          ├── web.php
      ├── Tests/
      ├── composer.json
      ├── module.json
      ├── package.json
      ├── webpack.mix.js

Check the documentation on how to use it: https://docs.laravelmodules.com/v9/creating-a-module

Also laravel-daily made a video on what it is here: https://www.youtube.com/watch?v=RVApkrYMcAg

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.