I am trying to dispatch a Laravel job inside a foreach loop. But the problem is, when I dispatch job inside loop sometimes it is completed before jobs queued before it are completed. What I want that is jobs should be completed one by one. Like happens in the chain method. But How I chain the same job inside the foreach loop? Is this possible?
foreach ($consignments as $consignment) {
CalculateSingleConsignment::dispatch($consignment, $total_consignments, $i, $user_id, $notify)->onQueue('invoice');
$i++;
}