keenminded
How to use Laravel 11 Context for Multi-Tenancy with Filament Panels?
Well, I wanted to have a main panel to manage tenants. Then tenants would have their panel and, using their subdomain, determine the tenant in the middleware and pass that info to the panel configuration. For example, as simple as having tenant's name as the title of the panel. I tried for a while, but then ended up going the tenancy package route. This was attempted using Laravel 10. Now with 11 I am trying to figure out how to use Context facade to determine the tenant and pass it in.
6 replies
How to use Laravel 11 Context for Multi-Tenancy with Filament Panels?
Hopefully, we can figure this out and post our findings here. I got things working with the tenancyforlaravel package, but it was an overkill. My other issue was that I couldn't pass tenant information to Panels because, from what I understand, the Panel builder executes before the middleware/tenancy providers, and the tenant ID was always null.
6 replies
Implement Pending Approval Page For Newly Signed up Users
@atom One thing I would recommend, for consistency with all other middleware and to ease your pains in debugging in the future, is always to keep the line return $next($request) as last in your middleware. This is the line that ties your middleware to the next one on the list, and as such, it is a good idea to keep it unchanged at the end of the handle method. Then, you would reverse your if statement to check for the absence of permissions.
Also, for consistency and readability, change the attribute to a method. This way, you can easily replace or extend the logic in your model rather than hunt down all references to user_approved_at. It also reads better, but that's more of a personal preference than a convention.
So, I would rewrite your middleware like so:
These small changes and consistency in the overall code base will make you, or anyone else working on your code, appreciate your efforts in the long run when you have to debug or test something. I hope this helps, and best of luck in your programming voyages.
23 replies