DEV Community

Miguel López
Miguel López

Posted on

Filament v3 - Multi-tenancy form component scoping

Multi-Tenancy feature

After following the documentation of Multi-Tenancy everything works well until I started to follow the demo project using the learned on the tenancy part :D

All the forms were automagically scoped with the current tenancy value, but once I started to use the modals forms I started to got some errors like

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "team_id" of relation "owners" violates not-null constraint DETAIL:

This is because Filament does not currently provide this feature on some component forms as we can read here.

The solution for this, is use the createOptionUsing method on the Filament\Forms\Components\Select component as we can see in the documentation.

So I put this code instead:

->createOptionUsing(fn ($data) => Filament::getTenant()->owners()->create($data)->id)

And the tenant value was saved correctly :).

All this wasn't my idea, I posted this issue as a bug on the github and I received this solution haha.

https://github.com/filamentphp/filament/issues/11709

I have shared this with you because if you encounter the same problem, I hope this explanation will help you.

Top comments (0)