[英]groupBy with eloquent relationship in laravel
我正在嘗試為我的發票頁面獲取數據,其中我針對單個發票編號使用了許多附加行。 我獲取了數據,但問題是我無法在發票視圖頁面中顯示附加的行。 為了獲得預期的結果,查詢應該寫什么,請問有人可以幫我嗎? 我的數據庫表是-
在我的控制器中,我嘗試了類似的操作-
public function orderProformaInvoiceDetails($poi)
{
$orderProformaInvoiceDetails = OrderProformaInvoice::where('opi_id', $poi)
->with('buyer', 'buyerJobs', 'buyerOrders')
->groupBy('invoice_no')
->orderBy('created_at', 'DESC')
->get();
return view('admin.marchendaising.order-proforma-invoices.details', compact('orderProformaInvoiceDetails'));
}
您應該將查詢結果分組:
OrderProformaInvoice::where('opi_id', $poi)
->with('buyer', 'buyerJobs', 'buyerOrders')
->orderBy('created_at', 'DESC')
->get()
->groupBy('invoice_no');
@foreach($orderProformaInvoiceDetails as $invoice_no => $details)
@foreach($details as $detail)
{{ $detail->quantity }}
@endforeach
@endforeach
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.