简体   繁体   English

与laravel雄辩的关系

[英]groupBy with eloquent relationship in laravel

I am trying to fetch data for my invoice page wherein I used many appended rows against single invoice number. 我正在尝试为我的发票页面获取数据,其中我针对单个发票编号使用了许多附加行。 I fetched data but the problem is I can not show the appended rows in invoice view page. 我获取了数据,但问题是我无法在发票视图页面中显示附加的行。 What should be written the query to get the expected result, Would someone help me, please? 为了获得预期的结果,查询应该写什么,请问有人可以帮我吗? My database table is - 我的数据库表是- order_proforma_invoices

And I am expecting like below what I did during crate- 我期望像下面在箱子里所做的那样- 查看页面

In my controller, I tried something like this- 在我的控制器中,我尝试了类似的操作-

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'));
}

You should group the query result: 您应该将查询结果分组:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM