Tenancy: associate created record with tenant in CreateAction

Hello,

How can we efficiently link a tenant to a record when it's being generated via a CreateAction, especially within the relationship manager context?

Currently, if someone initiates a new resource item within the relationship manager, this item doesn't get linked with their respective account.

Please note, the subsequent code snippet from handleRecordCreation isn't being executed:
if ($tenant = Filament::getTenant()) {
    return $this->associateRecordWithTenant($record, $tenant);
}
Solution
Thanks for the reply, I'm adding this comment to help users with the same problem.

Since my model is already very complicated I didn't want to add a trait to it. What I did is I used the after hook.

use Filament\Facades\Filament;

Tables\Actions\CreateAction::make()
   ->after(function ($record) {
       if (Filament::getTenant() !== null) {
           $record->teams()->attach(Filament::getTenant()->id, ['role' => 'administrator']);
       }
   }),
Was this page helpful?