Video Course

Build a Monthly Subscription App with Laravel Cashier: Lesson 34 of 36

Invoices

Up Next

Deleting Subscription

Autoplaying in 7 seconds!

Cancel

To download invoices, Laravel will automatically bring in dompdf in order to create the invoices. If you are getting errors that the package is not installed, be sure to install it using composer from the command line:

composer require dompdf/dompdf

After that, you'll need a route:

// download pdf
Route::get('account/invoices/{invoice}', 'AccountController@downloadInvoice');

Also, the controller code to download the PDF:

public function downloadInvoice($invoiceId)
{
    return Auth::user()->downloadInvoice($invoiceId, [
        'vendor'  => 'Animalgram',
        'product' => 'Monthly Subscription'
    ]);
}

Then a link to that route:

<a href="/account/invoices/{{ $invoice->id }}">Download</a>

Chris Sevilleja

162 posts

Co-founder of Scotch.io. Slapping the keyboard until something good happens.