2 回答
TA贡献2065条经验 获得超14个赞
您想更新所有收到的发票的信息,但将唯一未支付的发票保存到$this->filteredResults. 您可以在$this->saveInvoices()方法中移动“过滤器逻辑” ,这将解决问题。
$response = collect(\GuzzleHttp\json_decode($response->getBody()->getContents()));
$this->saveInvoices($response);
public function saveInvoices($invoices)
{
foreach ($invoices as $item) {
//If it wasn't paid and dueDate not passed, then save it to $this->filteredResults
if(($item['paid'] === false) && ($item["dueDate"] <= $now)){
$collection = collect($item);
array_push($this->filteredResults, $collection->only(['invoiceNumber', 'customerId', 'customerName', 'dueDate', 'invoiceDate', 'amountInOriginalCurrency', 'paid'])->toArray());
}
//Then update invoice information, regardless of paid status
UnpaidInvoices::updateOrCreate(
['invoiceNumber' => $item['invoiceNumber']],
['invoiceNumber' => $item['invoiceNumber'],
'customerId' => $item['customerId'],
'customerName' => $item['customerName'],
'dueDate' => $item['dueDate'],
'invoiceDate' => $item['invoiceDate'],
'amountInOriginalCurrency' => $item['amountInOriginalCurrency'],
'paid' => $item['paid']]);
}
}
TA贡献1876条经验 获得超5个赞
确保您在 DB 中设置了良好的索引。
仅从后端返回您真正需要的内容(前端没有过滤)
在检索集合/数组后,更新记录更改应是一个单独的调用,可能最简单的方法是再次调用以获取最新结果(第 1 点)。
添加回答
举报