【发布时间】:2021-07-18 09:48:03
【问题描述】:
我有以下代码用于从数据库中获取数据,
$invoices = SalesInvoices::where('is_invoice', 1)
->join('customers', 'customers.customer_id', '=', 'sales_invoices.customer_id')
->join('sales_payments', 'sales_payments.invoice_id', '=', 'sales_invoices.invoice_id')
->orderBy("sales_payments.created_at", "desc") //Get the latest updated payment for view in table for just 1 row.
->get();
Sales_payments 表具有不同的付款阶段,其中包含多个条目,例如 Received、Partial、Completed 等,每个阶段数据行都有invoice_id,这是SalesInvoices 的主键。
现在我在DataTables 中显示所有发票,但是使用上面的代码,我得到sales_payments 的所有值,但我只需要最后更新的条目,它具有最新的created_at。
如何在Sales_payments中只获得一个发票行但最新的付款状态,
谢谢,
【问题讨论】: