Martin1182
1 month ago
165
1
Laravel

Generate PDF invoice

Posted 1 month ago by Martin1182

Good day

Can you advise me on the best way to add another $ products variable to the function? I need the invoice blade then run through the foreach table of products. well thank you

class InvoiceController extends Controller
{
    public function downloadPDF($id)
    {
        $order = Order::find($id);
        $pdf = PDF::loadView('invoice', compact('order'));

        return $pdf->download('invoice.pdf');
    }
}

That's not how it works for me


class InvoiceController extends Controller
{
    public function downloadPDF($id)
    {
        $order = Order::find($id);
        $products = $order->products;
        $pdf = PDF::loadView('invoice', compact('order', 'products'));

        return $pdf->download('invoice.pdf');
    }
}

Please sign in or create an account to participate in this conversation.