-
|
In https://nova.laravel.com/docs/4.0/actions/defining-actions.html#job-batching, it is not showing clearly how to add a job to a batch through public function handle(ActionFields $fields, Collection $models)or at least pass the $models collection to public function withBatch(ActionFields $fields, PendingBatch $batch)I need to send emails to each selected user and get notified that the batch has been finished after all the emails are sent. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
|
Regarding
I'm not sure if I misunderstand the question, but if you look in the |
Beta Was this translation helpful? Give feedback.
-
|
I've spent a few hours today, further digging in to this now. Like mentioned earlier, Upon further granular testing, I was able to confirm my theory in an earlier message in this discussion
This is also perfectly fine as this is how Laravel is designed. Besides - we need to dispatch the Batch in order to get an ID in the first place. I also tested my code snippet in an earlier message in this discussion, albeit slightly modified. // `\Laravel\Nova\Actions\CallQueuedAction::handle()` (line 48-56 in Nova 4.13)
$this->callAction(function ($action) {
if (\in_array(Batchable::class, \class_uses_recursive($action))) {
$action->withBatchId($this->batchId);
}
return $action->withActionBatchId($this->actionBatchId)->{$this->method}($this->fields, $this->models);
});This makes it work, and I haven't seen any side effects so far. // TestQueuedAction
public function handle()
{
if ($this->batching()) {
$this->batch()->add(new TestBatchJob);
}
}
I've commited the repo I used to test things. I'm not sure if I should keep this message here, start a feature request, or file a bug report.
Sorry for pinging, but, @crynobone or @davidhemphill could maybe give me a pointer, if I should post elsewhere, or so. |
Beta Was this translation helpful? Give feedback.
-
|
@FSElias This has now been implemented, in Nova 4.14. 🙂 I haven't tested it yet, but we should now be able to access the Batch in the Action's |
Beta Was this translation helpful? Give feedback.
@FSElias This has now been implemented, in Nova 4.14. 🙂
I haven't tested it yet, but we should now be able to access the Batch in the Action's
handle()method.