Post

Coming in the next version of Lucid: First-class support for Multi-Tenant applications! With built-in Dependency Injection, you can effortlessly create a custom QueryClient that automatically applies the right query constraints for each tenant. Learn more 👇

1. Define a middleware that creates an instance of QueryClient and auto adds the `where tenant_id clause` to all the queries. 2. Bind this instance of the QueryClient to the container.

All other parts of your application using DI will receive the same QueryClient instance during the current HTTP request. For example, here I am fetching all the posts for a given tenant without remembering to always add this clause.

This global where clause can bite you if there are `or where` conditions in your query. To mitigate that, we are removing the top-level `orWhere` method from the query builder, and you will be forced to always define a `orWhereGroup` to write or where conditions.

0 reposts1 like

No replies yet.