FilamentF
Filament7mo ago
bouly

Define multi-tenant relationship indirectly through another model

Hello,

I'm working with Filament's multi-tenancy features and I have a question about defining tenant ownership relationships.

In my app:
  • A User belongs to a Team (with a team_id column).
  • A Post belongs to a User (with a user_id column).
  • A Post does not have a team_id column directly.
I would like Filament to treat a Post as belonging to a Team, but indirectly via its related User.
Is it possible to define the ownership relationship in this way, without adding a direct team_id column to the posts table?

I would define something like this, in the Post model:
public function team()
{
    return $this->hasOneThrough(
        Team::class,
        User::class,
        'id',
        'id',
        'user_id',
        'team_id'
    );
}


Thanks for your help!
Was this page helpful?