FilamentF
Filamentโ€ข3y ago
Daniel Plomp

Enable/Disable button dynamically (based on Job Status)

I have created an Action inside my ListPage Header (headerActions). This action is firing a Batch Job. What I really would like is some way to disable the button (and show a loading indicator icon) during the time this job runs. When it is finished, it should be enabled again.
Not sure how to achieve this. I can of course check if the job runs and prevent users from starting another one, but it would be nice to make it visible.

I tried something with the ->disabled(fn () => $this->checkIfJobIsRunning), but how can I make this dynamic?

/**
 * @return bool
 * Simple version
 */
protected function checkIfJobIsRunning(): bool
{
    $batchName = 'URL check';
    $batch = DB::table('job_batches')->where('name', $batchName)->first();

    return $batch && ! $batch->cancelled && ! $batch->finished_at;
}


Any ideas?
Was this page helpful?