Why is my Action visible?

Hi, I have a InfoList with an action, but why is my action button (edit:not) visible? I dumped $record and the $record->status is 'running'.
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make('Rate limiting')
->description('Rate limiting settings for this instance.')
->headerActions([
Action::make('stopInstance')
->visible(fn ($record) => $record->status === 'running')
->action(function ($record) {
$record->update(['status' => 'stopped']);
})
->icon('heroicon-m-stop')
->color('danger')
->requiresConfirmation()
])
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make('Rate limiting')
->description('Rate limiting settings for this instance.')
->headerActions([
Action::make('stopInstance')
->visible(fn ($record) => $record->status === 'running')
->action(function ($record) {
$record->update(['status' => 'stopped']);
})
->icon('heroicon-m-stop')
->color('danger')
->requiresConfirmation()
])
The action button should not be visible...
Solution:
Thank you guys! I found my mistake... I forgot that status is an ENUM. Thanks to your help I was able to fix it: ->visible(fn ($record) => $record->status === InstanceStatus::RUNNING)...
Jump to solution
8 Replies
Dennis Koch
Dennis Koch8mo ago
You literally instruct it to be visible when status is running.
Soldges
SoldgesOP8mo ago
Oh sorry... my text was wrong... I mean "Why is my action button not visible".... My mistake. So with the code above the action button is not visible...
Dennis Koch
Dennis Koch8mo ago
And status is a string? The value is not changed during the page visit but is running already when you visit that page.
Soldges
SoldgesOP8mo ago
Yes. Status is a string. And I am Not changing that value in the visit site
LeandroFerreira
LeandroFerreira8mo ago
Are you sure it is showing running?
Action::make('stopInstance')
->label(fn (?Model $record): string => 'Stop '.$record?->status)
Action::make('stopInstance')
->label(fn (?Model $record): string => 'Stop '.$record?->status)
What is the output?
Solution
Soldges
Soldges8mo ago
Thank you guys! I found my mistake... I forgot that status is an ENUM. Thanks to your help I was able to fix it: ->visible(fn ($record) => $record->status === InstanceStatus::RUNNING)
Dennis Koch
Dennis Koch8mo ago
That’s why I asked whether it’s a string 😅
Soldges
SoldgesOP8mo ago
you are so right 😁 I only checked the database field and not my actual code. I sorry. You guys rock!
Want results from more Discord servers?
Add your server