jeudi 7 septembre 2017

Laravel generate pdf using laravel-dompdf

I have to generate a invoice in my application, i have integrated the barryvdh/laravel-dompdf

public function invoice($order_id)
{
    $invoice_order = Order::leftJoin('users', 'users.id', 'orders.user_id')
                          ->where('orders.id', $order_id)
                          ->select('orders.id','delivery_boy_id','name','phone_number','orders.address','orders.city','orders.pincode','delivery_time_slot','total')
                          ->first();

    $invoice_order_details = OrderDetail::leftJoin('products', 'products.id', 'order_details.product_id')
                                        ->where('order_id', $order_id)
                                        ->select('products.id','name','proportion','price','quantity')
                                        ->get();

    $sub_total = OrderDetail::leftJoin('products', 'products.id', 'order_details.product_id')
                            ->where('order_id', $order_id)
                            ->sum(\DB::raw('(products.price) * (quantity)'));

    $invoice_to_pdf = $this->invoiceToPdfGenerate($invoice_order, $invoice_order_details, $sub_total);

    return view('pages.manager.orders.invoice', compact('invoice_order','invoice_order_details','sub_total'));
}

public function invoiceToPdfGenerate($invoice_order, $invoice_order_details, $sub_total)
{
    $pdf = \PDF::loadView('pages.manager.orders.invoice', $invoice_order, $invoice_order_details, $sub_total);
    return $pdf->download('invoice.pdf');
}

when i tried to load the view i'm getting the following error

(1/1) ErrorException
array_merge(): Argument #1 is not an array
in Factory.php (line 134)

i did tried by converting the arguments to array like $invoice_order = $invoice_order->toArray(); but still same error

need some help with this

than you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire