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