Filter Filament Project Resources Based on Authenticated User's Team
I'm working on a Laravel application with a Filament admin panel. I need to filter the projects displayed in the admin panel so that only projects related to the authenticated user's team are shown. Here's a summary of my setup and what I've tried so far:
Database Schema:
User: belongs to a Team
Team: has many Users and Projects
Project: belongs to a Team
Could someone guide me on the correct approach ?
Thank you!
5 Replies
User -> Teams -> Projects : auth()->user()->teams->projects : I suppose it would be this , the list of projects in a select. May be you probably need tenants
Thanks, I used global scope to ensure that the filtering is applied consistently across all queries for the Project model
@karim_Jäger Here's a good read. This will guide you to implement multi-tenancy and keep projects scoped to the user's team
https://filamentphp.com/docs/3.x/panels/tenancy#simple-one-to-many-tenancy
I would recommend sticking with Simple Tenancy (one-to-many). This is way simpler than using filament's Multi-Tenancy which doesn't seem to be neccesary given your database schema
Thank you, I'll look into it , appreciate it