Menu

πŸ“°
0

11 Middlewares and 6 Traits That Power a Multi-Tenant Laravel SaaS

DEV Community: sassΒ·Dmitry IsaenkoΒ·about 1 month ago
#sHyqFb0Z
#dev#php#saas#middleware#larafoundry#class
Reading 0:00
15s threshold

Every request in a multi-tenant SaaS needs to answer a dozen questions before your controller runs. Which company context? Is the session valid? Is the user banned? Has the subscription expired? Should the screen be locked? What language? I built Kohana.io - a production CRM/ERP - and ended up with 11 custom middlewares and 6 traits. Not because I wanted to over-engineer, but because each one solved a recurring problem. Now I'm extracting them into LaraFoundry , an open-source SaaS framework for Laravel. This post covers the full middleware stack, all custom traits, and the design decisions behind them. The Middleware Stack Order matters. Here's the complete stack with execution sequence: 1. HandleInertiaRequests β†’ shares props with Vue frontend 2. SetActiveCompanyMiddleware β†’ resolves company context 3. UpdateLastSessionActivity β†’ tracks activity + device info 4. AddLinkHeadersForPreloadedAssets β†’ HTTP/2 push 5. StoreIntendedUrl β†’ saves URL for post-auth redirects 6. SetLocale β†’ detects language 7.…

Continue reading β€” create a free account

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

Read More