Conditionally hide action button.

I have created an Action. Everything is working fine with the code below. When the action button is used the modal appears, and after confirming 'marked_ready_at' gets the current date/time.
protected function getActions(): array
{
return [
Action::make('Mark Ready')
->action(function (array $data): void {
$this->record->marked_ready_at = now();
$this->record->save();
$this->refreshFormData([
'marked_ready_at',
]);
})
->requiresConfirmation()
->modalHeading('Booking Ready')
->modalSubheading('Are you sure.')
->modalButton('Yes, it\'s ready'),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
protected function getActions(): array
{
return [
Action::make('Mark Ready')
->action(function (array $data): void {
$this->record->marked_ready_at = now();
$this->record->save();
$this->refreshFormData([
'marked_ready_at',
]);
})
->requiresConfirmation()
->modalHeading('Booking Ready')
->modalSubheading('Are you sure.')
->modalButton('Yes, it\'s ready'),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
I want to hide or disable the action button "Mark Ready" when "marked_ready_at" has a date/time. Any suggestion on how I can achieve this? Thanks.
Solution:
use ->hidden(fn () => (bool) $this->record->marked_ready_at)
Jump to solution
4 Replies
Solution
Saade
Saade16mo ago
use ->hidden(fn () => (bool) $this->record->marked_ready_at)
Saade
Saade16mo ago
or ->disabled the same way
Pablo Torres
Pablo TorresOP16mo ago
Thank you so much... it worked nicely.
Want results from more Discord servers?
Add your server