doucheng1884 2018-05-17 06:52
浏览 50
已采纳

在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- view page

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'));
}
  • 写回答

1条回答 默认 最新

  • dongmu1390 2018-05-17 15:23
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?