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 Koch3mo ago
You literally instruct it to be visible when status is running.
Soldges
Soldges3mo 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 Koch3mo 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
Soldges3mo ago
Yes. Status is a string. And I am Not changing that value in the visit site
LeandroFerreira
LeandroFerreira3mo 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
Soldges3mo 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 Koch3mo ago
That’s why I asked whether it’s a string 😅
Soldges
Soldges3mo ago
you are so right 😁 I only checked the database field and not my actual code. I sorry. You guys rock!