F
Filament3mo ago
Abi

Multi Tenancy associate Tenant to Resource

I have created a model that has a team_id column and also a team() relation to the Team model. The Team model has been setup as the tenant model on the Provider.
//AdminPanelProvider.php
$panel->tenant(model: Team::class, slugAttribute: 'slug', ownershipRelationship: 'team')
//AdminPanelProvider.php
$panel->tenant(model: Team::class, slugAttribute: 'slug', ownershipRelationship: 'team')
Do I need to do anything else in each resource to associate the tenant id for the CRUD operations? I get this error when I create a new record on a resource inside the Multi Tenancy Panel
SQLSTATE[HY000]: General error: 1364 Field 'team_id' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'team_id' doesn't have a default value
Any advice?
4 Replies
Abi
Abi3mo ago
OK, I actually figured out the issue. Not sure if this is a bug. When I use the CreateAction that is setup on the ListResource class, the record gets created correctly. But, if I use the same CreateAction on the emptyStateActions for the Table class, then the tenancy doesn't get associated. Do I need to do anything extra? Here is the code to my emptyStateActions method
->emptyStateActions([
Tables\Actions\CreateAction::make()
->label('Create your first speaker')
->modalHeading('Create a new Speaker')
->modalWidth('2xl'),
])
->emptyStateActions([
Tables\Actions\CreateAction::make()
->label('Create your first speaker')
->modalHeading('Create a new Speaker')
->modalWidth('2xl'),
])
Abi
Abi3mo ago
I am assuming there is tenancy association happening on the ListResource class here https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Resources/Pages/ListRecords.php#L109. Does this also need to be done when using the createAction on emptyState sections?
GitHub
filament/packages/panels/src/Resources/Pages/ListRecords.php at 3.x...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Abi
Abi3mo ago
the relationship method is being used https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Resources/Pages/ListRecords.php#L120 to assign the tenant, but I can't seem to find that on the Tables\Actions\CreateAction class @Dan Harrin @Leandro Ferreira any advice is much appreciated.
Carl-bot
Carl-bot3mo ago
.abishek has been warned, this is their first warning.