F
Filamentβ€’7mo ago
ericmp

Import csv on relation manager, how to refresh table after importing?

https://filamentphp.com/community/how-to-refresh-widgets-when-table-actions-are-fired im trying to follow it but applying it into my case. my case: import action on a relation manager table - refresh the table once the importation has finished code:
// app/Filament/Resources/EventResource/RelationManagers/ContactsRelationManager.php
protected $listeners = ['refreshContactsRelationManagerTable' => '$refresh'];
// app/Filament/Resources/EventResource/RelationManagers/ContactsRelationManager.php
protected $listeners = ['refreshContactsRelationManagerTable' => '$refresh'];
(https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#lifecycle-hooks)
// app/Filament/Imports/ContactsImporter.php
protected function afterSave(): void
{
$this->emit('refreshContactsRelationManagerTable');
}
// app/Filament/Imports/ContactsImporter.php
protected function afterSave(): void
{
$this->emit('refreshContactsRelationManagerTable');
}
but the table doesnt reload. i guess this is because it depends on the notification that has been sent. so im not sure how to emit it also in the notification or something similar
6 Replies
LeandroFerreira
LeandroFerreiraβ€’7mo ago
Laravel
Events | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
ericmp
ericmpOPβ€’7mo ago
cant make it work. i guess, as said, that it depends on the db notifications. so idk how to listen to them. i understand that the notifications are shown when polling (by default 30 seconds) i think that what i wanna achieve is not possible (without websockets) also, in the app/Filament/Imports/ContactsImporter.php file seem si cant use $this->emit
Call to undefined method App\Filament\Imports\ContactsImporter::emit()
Call to undefined method App\Filament\Imports\ContactsImporter::emit()
Tetracyclic
Tetracyclicβ€’7mo ago
The Importer classes aren't Livewire components, they're just plain PHP classes.
ericmp
ericmpOPβ€’7mo ago
true πŸ˜… hmmm then, not sure how to achieve it. well, the users will have to reload the page for now i think. ill add a notification so they know it
Tetracyclic
Tetracyclicβ€’7mo ago
Yeah, you would need something on the page that can detect when the background import job actually finishes, either somehow detecting the database notification getting pulled in, or custom code to poll it or listen for a broadcast event and trigger the refresh. The simplest solution might just be to edit the notification message to tell the user to refresh to see the new records.
ericmp
ericmpOPβ€’7mo ago
yeah im gonna do the 2nd thanks! (:
Want results from more Discord servers?
Add your server