F
Filament14mo 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
ChriisOP14mo ago
I have this error
No description
toeknee
toeknee14mo ago
Because you are calling $livewire then activeTab and activeTab is not designed on the $livewire element.
Chriis
ChriisOP14mo 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
toeknee14mo ago
id you dd($livewire) ?
Chriis
ChriisOP14mo ago
I have that 😅
No description
toeknee
toeknee14mo ago
Scroll down and it will show the error…. You know what DD is right?
awsqed
awsqed14mo 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
ChriisOP14mo ago
There was no error returned in the DD message ... It worked, thx a lot 🙂

Did you find this page helpful?