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

neowill2013's avatar

Non-static method should not be called statically

I want to generate PDF file from a view in laravel 5.1. I'm using https://github.com/barryvdh/laravel-dompdf

But, Im getting following error: Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically, assuming $this from incompatible context

$pdf = PDF::loadView('invoices.show_invoice', $data);
return $pdf->download('invoice.pdf');
0 likes
4 replies
phildawson's avatar
Level 26

Looks to me like you are using the class directly. You'll need to use the facade if you want to call the methods statically.

Either:

use Barryvdh\DomPDF\Facade as PDF;

or

You can optionally use the facade for shorter code. Add this to your facades:

'PDF' => 'Barryvdh\DomPDF\Facade',

If you don't want to use the facade you can resolve the PDF instance using.

$pdf = app('dompdf.wrapper');
$pdf->loadView('invoices.show_invoice', $data);
3 likes
RushVan's avatar

I have the same issue. I can resolve the non-static method error.

If I apply the last option and not use the facade, I get this;

Class dompdf.wrapper does not exist

??

Any ideas? Thanks.

gsantos's avatar

Excellent, @phildawson. As simple as it looks the solution you gave was so usefull to me! Thank you so much!

pcartagena's avatar

I'm having the same issue but I already havethe

'PDF' => 'Barryvdh\DomPDF\Facade', line in app.php

as well as the accompanying provider line: Barryvdh\DomPDF\ServiceProvider::class,

Why would this error be happening in that case?

Please or to participate in this conversation.