F
Filament13mo ago
Chriis

Accessing $livewire in emptyStateDescription() method

Hi, is it possible to acces $livewire into the emptyStateDescription() method of a table ?
->emptyStateDescription(function (Livewire $livewire): string {
$activeTab = $livewire->activeTab;

$description = match ($activeTab) {
'validated' => 'Aucune fiche(s) trouvé',
'pending' => 'Aucune fiche(s) en attente',
'archived' => 'Aucune fiche(s) archivé(s)',
};

return $description;
});
->emptyStateDescription(function (Livewire $livewire): string {
$activeTab = $livewire->activeTab;

$description = match ($activeTab) {
'validated' => 'Aucune fiche(s) trouvé',
'pending' => 'Aucune fiche(s) en attente',
'archived' => 'Aucune fiche(s) archivé(s)',
};

return $description;
});
8 Replies
Chriis
ChriisOP13mo ago
I have this error
No description
toeknee
toeknee13mo ago
Because you are calling $livewire then activeTab and activeTab is not designed on the $livewire element.
Chriis
ChriisOP13mo ago
Well this is working so I thought I could use it also with emptyStateDescription but the $livewire element must be unavailable in this context 🫤
Tables\Actions\DeleteBulkAction::make()
->hidden(fn ($livewire) => $livewire->activeTab === 'archived')
Tables\Actions\DeleteBulkAction::make()
->hidden(fn ($livewire) => $livewire->activeTab === 'archived')
toeknee
toeknee13mo ago
id you dd($livewire) ?
Chriis
ChriisOP13mo ago
I have that 😅
No description
toeknee
toeknee13mo ago
Scroll down and it will show the error…. You know what DD is right?
awsqed
awsqed13mo ago
try using
->emptyStateDescription(function (\Filament\Tables\Table $table): string {
$livewire = $table->getLivewire();
$activeTab = $livewire->activeTab;

$description = match ($activeTab) {
'validated' => 'Aucune fiche(s) trouvé',
'pending' => 'Aucune fiche(s) en attente',
'archived' => 'Aucune fiche(s) archivé(s)',
};

return $description;
});
->emptyStateDescription(function (\Filament\Tables\Table $table): string {
$livewire = $table->getLivewire();
$activeTab = $livewire->activeTab;

$description = match ($activeTab) {
'validated' => 'Aucune fiche(s) trouvé',
'pending' => 'Aucune fiche(s) en attente',
'archived' => 'Aucune fiche(s) archivé(s)',
};

return $description;
});
Chriis
ChriisOP13mo ago
There was no error returned in the DD message ... It worked, thx a lot 🙂
Want results from more Discord servers?
Add your server