ImportAction in combination with tenancy

Today I've upgraded my side project to Filament V3.1 to toy around with the new ImportAction. The application uses the build in multi tenacy (tenant model named Organization) and a custom auth guard named 'organizer' (with auth model Organizer). With the application organizers within an organization can manage Spots. The idea is to make these spots importable using the new ImportAction. First error I encountered was I'd had to add $this->app->bind(Authenticatable::class, Organizer::class); to a service provider, otherwise the Import model could not resolve the "user". Is this intended? Secondly, The imported spots needs to be associated with the tenant (Organization). I've tried to receive to tenant using Filament::tenant() within the resolveRecord method, but this resolves to NULL. I think the reason is I'm using Horizon (Redis) as queue and Filament::tenant() only works on request lifecycle. How can I associate the current tenant to an imported record?
Solution:
`public function resolveRecord(): ?Participant { $participant = Participant::firstOrNew([ 'email' => $this->data['email'],...
Jump to solution
4 Replies
James
James8mo ago
Woo hoo I found an answer for this Tables\Actions\ImportAction::make() ->importer(ParticipantImporter::class) ->options(['tenant_id' => Filament::getTenant()->id]), Pass an options with the import action and then...
Solution
James
James8mo ago
public function resolveRecord(): ?Participant { $participant = Participant::firstOrNew([ 'email' => $this->data['email'], ]); $participant->trial_id = $this->options['tenant_id']; return $participant; }
James
James8mo ago
You can access this in the resolveRecord actions
Maarten Paauw
Maarten PaauwOP8mo ago
I forgot about this question and I think I end up with a similar solution. Great work!

Did you find this page helpful?