© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
Disouric

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
handleRecordCreation
isn't being executed:
if ($tenant = Filament::getTenant()) {
    return $this->associateRecordWithTenant($record, $tenant);
}
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
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']);
       }
   }),
use Filament\Facades\Filament;

Tables\Actions\CreateAction::make()
   ->after(function ($record) {
       if (Filament::getTenant() !== null) {
           $record->teams()->attach(Filament::getTenant()->id, ['role' => 'administrator']);
       }
   }),
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Multi Tenancy associate Tenant to Resource
FilamentFFilament / ❓┊help
2y ago
Access recently created record on CreateAction
FilamentFFilament / ❓┊help
3y ago
Disable tenant menu with tenancy
FilamentFFilament / ❓┊help
3y ago
Tenancy: access tenant in `canAccessPanel` function
FilamentFFilament / ❓┊help
3y ago