Pseudo multi tenant setup using panels w/ a parameter (or maybe something else?)
Heya everyone!
I'm in the process of upgrading from Filament v2, but I have a non standard setup and I am not able to port it to Filament v3.
Sorry for the wall of text, I'm gonna be as clear and concise as possible.
I have an internal admin-only dashboard, that has several "global" pages. One of those pages is a list of restaurants.
When navigating to the View page of a Restaurant, I move to a different "context" specific to that restaurant.
E.g. the links in the sidebar change and when opened the pages show data from that specific restaurant (their orders only, their holidays, etc..)
To be clear, this is not really a multi tenant setup: restaurant owners can't access Filament, it's only used internally to separate the data.
I achieved it by using the now deprecated https://github.com/artificertech/filament-multi-context plugin.
We have two contexts, one of them has a parameter to store the "current restaurant".
We then manipulate routes and filter resources using several custom traits/tricks, some of them a bit obscure (lots of trial and error).
Adding a pic for clarity.
Fast forward a few years, I'd like to upgrade to Filament v3 and my initial thought was to replicate it using two panels.
I tried adding a parameter to the route of the "nested" panel (
restaurants/{id}
) but it breaks a lot of stuff (login/logout links and more) and I would like to stay a bit more "vanilla".
Other things that look appropriate might be Clusters and/or Sub-Navigation, but after spending a few hours with those I haven't been able to make them work as I would like to.
I could try "hammering until it works" it but maybe you guys can suggest a better way?
Thanks!Solution:Jump to solution
Sorry for the late update, I've been busy these past few weeks.
Anyway, thanks for your suggestions!
I had already tried using clusters, but it looked like I could only use them to group resources when I would also like to scope the results by the current Restaurant.
...
4 Replies
Bump, any ideas?
I'm not super confident in my Filament knowledge, maybe I'm making it harder than it needs to be
Bump
Why not use the cluster menu instead? Or sub navigation and just have roles access for each of the menu items? i.e. if role = admin should all items in the left, if role = user show all int he right?
Else... Build it the same in two panels.
Idea:
- Add a middleware that checks, if you are on a Restaurant route
- Get current panel
Filament::getCurrentPanel()
- Overwrite the navigation using the navigation builder: https://filamentphp.com/docs/3.x/panels/navigation#advanced-navigation-customizationSolution
Sorry for the late update, I've been busy these past few weeks.
Anyway, thanks for your suggestions!
I had already tried using clusters, but it looked like I could only use them to group resources when I would also like to scope the results by the current Restaurant.
I also tried to implement Dennis's idea. Initially, it worked, but then I got stuck in a slew of Livewire errors that I was not able to solve. I still can't fully wrap my head around the Livewire stuff.
In the end, I managed to solve it using Multi-tenancy (not sure how I missed it the first time).
I set up two panels: an "admin" panel with all the global resources, and a "restaurants" panel with a Restaurant tenant configuration (that automatically scopes everything).
Setting up the links between the two panels was a bit tricky, but aside from that, the docs were very thorough, and I managed to do everything I wanted.
Thanks again for giving me some pointers!