Dynamic sidebar
I'm using Filament 3 and want the sidebar to include a "Channels" group with dynamic items loaded from the database (one per active channel of the authenticated user). The rest of the navigation should still work via discoverResources().
The problem is that I can’t access auth()->user() inside panel() because the user isn’t authenticated yet, so I can’t generate those items there.
Is there any recommended way to add user-specific dynamic items without breaking the default discovery and without overriding everything with navigationItems()?
Thanks!
Solution:Jump to solution
I finally found the solution. I used ServiceProvider instead of Middleware, and it worked perfectly.
Here's the code.
```php...
9 Replies
For that sir you need a middleware to do it 😉
similar to attached
customNavLinks is a relationship to a custom table.
thanks @toeknee I try this solution but Filament:getTenant() it's null. I put middleware on Panel Provider ->authMiddleware()
Hmm I am sure it gets hit eventually, I did see a current_tenant_id on the user model on my instant and used that to get the tenant
Using your idea, I was able to insert the channels into navigation items, but they are not visible in the side menu.
Create the group Channels first?
I add this on UserPanelProvider and it doesn't works... navigation items does not show
I have already been able to get your code @toeknee to work with the tenant (it should have been in tenantMiddleware()), but I still can't get the dynamic items to come out 😦
Solution
I finally found the solution. I used ServiceProvider instead of Middleware, and it worked perfectly.
Here's the code.
Thanks @toeknee
No problem! Glad you got it to work