F
Filament3mo ago
Steff

table row action to run a job?

I'm loocking for a table row action to run a job (script, service class...). I have a job (command) and i want run it with a click of a table row action. I need the record id in the script. i think the biggest challenge is the output of the success/failure message? how can i simply call a script is there an easy way? Something like that:
Action::make('run something')
->requiresConfirmation() // with or without
->action(fn ([Model] $record) => $record->[ run a job ])
Action::make('run something')
->requiresConfirmation() // with or without
->action(fn ([Model] $record) => $record->[ run a job ])
Does anyone have a tip for me?
Solution:
For example with the action-pattern $result = (new UpdateJobSearches)->run($record->id). Return the data you need and build your response with it.
Jump to solution
7 Replies
Dennis Koch
Dennis Koch3mo ago
Should it be sync or async/queued?
Steff
SteffOP3mo ago
Hm, i think sync.
Dennis Koch
Dennis Koch3mo ago
What are you currently using? A Command? I'd extract the common logic to a class and call it from both. It's not really a Filament issue, more of a code structure thing.
Steff
SteffOP3mo ago
Yes, currently a Command. And yes i want it to extract. i don't know, how to start the job or this class from the action and return a message. is there a rudimentary example? PS: The job searches the relevant rows of the client (multitenancy) and creates or updates relationships between the data records. this takes a few seconds.
Dennis Koch
Dennis Koch3mo ago
i don't know, how to start the job or this class from the action and return a message. is there a rudimentary example?
If you extract it, it's just calling your new class.
Solution
Dennis Koch
Dennis Koch3mo ago
For example with the action-pattern $result = (new UpdateJobSearches)->run($record->id). Return the data you need and build your response with it.
Steff
SteffOP3mo ago
Ok, i try it. Thx.
Want results from more Discord servers?
Add your server