Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EventFellows's avatar

Add invoice-table information to PDF invoice without hacking vendor files

I have additional fields on my incoices table that needs to be on the invoice PDF for legal reasons.

I have copied and changed the receipt.blade.php file to resources/vendor/cashier/receipt.blade.php so it gets used for any PDF invoices that are created without any problems. But unfortunately populating the $variables for this invoice-view happens deep inside Spark/ Cashier vendor code and I do not want o hack it there.

How can I get the information into the view? Any ideas or suggestions?

0 likes
3 replies
EventFellows's avatar
EventFellows
OP
Best Answer
Level 16

I belive the view::publish just does the exact same thing as manually putting the receipt.blade.php file to resources/vendor/cashier/receipt.blade.php so you can simply do that once by hand.

Here is how I sovled it: If you only need to customize the look of it, above file setup should be all you need. The challenge comes in if you need additional data on the PDF that is not passed in by default.

Out of the box the download is handled here: \vendor\laravel\spark\src\Http\Controllers\Settings\Billing\InvoiceController.php

To pass in additional data, this is what I ended up with.

  • create a new downoad route e.g. Route::get('/account/invoice/{uuid}', 'InvoiceController@download')
  • change the download URL in .js file according to your new route
  • run GULP (so the .js picks up the correct download URL for the invoice download buttons)
  • create a modified version of the original download method with all relevant $data that gets called with the new route

My Setup looks like this:

class InvoiceController extends Controller
{

    /**
     * Download the invoice with the given ID.
     *
     * @param  Request  $request
     * @param  string  $id
     * @return Response
     */
    public function download(Request $request, $uuid)
    {
        $invoice = $request->user()->localInvoices()
                            ->where('uuid', $uuid)->firstOrFail();

        $this->authorize('download-invoice', $invoice);

        return $request->user()->downloadInvoice(
            $invoice->provider_id, [
                'provider_id' => $invoice->provider_id, 
                'invoice_number' => $invoice->invoice_number, 
                'uuid' => $invoice->uuid ] + Spark::invoiceDataFor($request->user())
        );
    }
}

Pay attention that in this setup the old download route will not work any longer as there is some data missing that is used in the receipt view. This will affect the incoice attachments that are sent by spark as a default ( I did not want to send attachements anyways and therefore removed it anyways)

Please or to participate in this conversation.