Menu

1 / 5

Keep Tenancy Out of Your Laravel App: Structuring stancl/tenancy v4 as a Module

DEV Community: laravel·Abderrahim El Ouariachi·about 22 hours ago
#zifXMLTs
#devtolaravel#devto#dev#tenancy#fullscreen
Reading 0:00
15s threshold

When you develop a multi-tenant application, it's easy for the code of your central application to get entangled with the tenant code. Or you start splitting everything into Central and Tenant folders.

Models |-> Central |-> Tenant

Enter fullscreen mode

Exit fullscreen mode

but there is a better way: modules.

In this post, we will talk about how to do that.

The stack I'm using:

Laravel 13

stancl/tenancy v4

Pest 4

How a module is usually structured

First, we need to decide on a structure. Most developers structure their modules like this:

Modules/Billing/ ├── src/ │ ├── Domain/ │ ├── Application/ │ └── Http/ ├── config/ ├── database/ ├── routes/ └── tests/

Enter fullscreen mode

Exit fullscreen mode

I decided to structure it differently, using the structure you are already used to working with: the default Laravel structure.

modules/ └── Tenancy/ ├── app/ │ ├── Http/ │ │ └── Controllers/ │ │ └── Controller.php │ ├── Models/ │ │ ├── SomeModel.php │ │ └── AnotherModel.php │ └── Providers/ │ ├──…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.