我有一个函数,我从数据库中获取订单,然后使用它们一次转到10个。如果我有100个订单,我相信会发生的流程是get将被调用10次(因为有100个订单)。
现在,一旦完成,我希望能够访问 $totalOrders.这可能吗?getUnfilledOrderschunkcheckStatuscheckStatusgetUnfulfilledOrders
protected function getUnfulfilledOrders()
{
Order::where('order_status', '!=', true)
->where('tracking_number', '!=', null)
->limit(3000)
->chunk(10, function ($unfulfilledOrders) {
$this->checkStatus($unfulfilledOrders);
});
// how to do something now with $totalOrders once ALL Orders are processed 10 at a time;
}
protected function checkStatus($unfilledOrders)
{
$totalOrders = array();
foreach ($unfulfilledOrders as $unfulfilledOrder) {
// logic here
array_push($totalOrders, $unfulFilledOrder->id);
}
}
墨色风雨