FilamentF
Filament15mo ago
Matthew

Table Actions and making variables more efficient

Interested in any opinions on how people avoid repeating code for issues where a table action, and elements of that are dependent on the status of $record

For example, if:

Action::make('test')
->button()
->label(function ($record) :string {

if ($record->isTypeA()) 
  {return 'Some text';
})

if $record->isTypeB())
{return 'Some different text';
})

->tooltip(function ($record) :string {

if ($record->isTypeA()) 
  {return 'Some tootip text';
})

if $record->isTypeB())
{return 'Some different tooltip text';
}),


Obviously a very basic example, but when you start adding a lot more methods, and increasing the complexity of the options, it can feel very cluttered and inefficient.

How do people go about extracting some of this logic for the $record?
Was this page helpful?