Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically I want to export pdf for each report from logined a user.
Look at my codes.
my blade
<a class="btn btn-primary btn-sm" href="{{ route('report.export-pdf') }}">Download PDF</a>
web.php
Route::get('report/export-pdf', 'ReportController@export_pdf')->name('report.export-pdf');
ReportController.php
public function export_pdf(Report $report)
{
$report = Report::findOrFail($report);
$pdf = PDF::loadView('Home.report')->setPaper('a4', 'portrait');
$fileName = $report->issue_number;
return $pdf->stream($fileName.'.pdf');
}
You probably imported the wrong class or you didn't register the facade itself!
If you added the facade in config/app.php you need to do this at the top of your controller
use PDF;
If you want to point to the specific facade class you need to do this
use Barryvdh\DomPDF\Facade as PDF;
@BOBBYBOUWMANN - I use laravel 5.8 and I added use Barryvdh\DomPDF\PDF; in my controller.
@irankhosravi You can only call static methods on the facade. Otherwise you need to do this:
$pdf = app('dompdf.wrapper');
$pdf->loadView('view');
@irankhosravi actually call you can call it like this:
$pdf = \App::make('dompdf.wrapper');
$pdf->loadView('invoices.credit_note', compact('credit_notes'));
$pdf->save(public_path($path));
Hope it helps!
@AURAWINDSURFING - I'm not sure why anyone would want to use that approach in Laravel 5. app() and resolve() are helpers to App::make() and a facade doesn't need to be imported.
Use @bobbybouwmann 's approach, resolving it via the service container using the helper method.
@irankhosravi - I'm not sure what is the main problem.
but please try this.
change your namespace after try.
use Barryvdh\DomPDF;
@BOBBYBOUWMANN - I get this error.
Undefined variable: order (View: C:\xampp\htdocs\urmiahardware\magzrayaneh\resources\views\Home\report.blade.php)
Then I changed this my codes.
public function export_pdf(Order $order)
{
$report = Report::findOrFail($order);
//$pdf = PDF::loadView('Home.report')->setPaper('a4', 'portrait');
$pdf = app('dompdf.wrapper');
$pdf->loadView('Home.report');
$fileName = $report->issue_number;
return $pdf->stream($fileName.'.pdf');
}
@JAYTEE - I hear you but if I remember well it did not work and that was why I did it that way. Not 100% sure tough
@irankhosravi I'm not sure what you're trying to do here. You dependency inject an order here based on the url, but then want to get a report. This bit of code won't work as well!
just use this in controller it will fix the problem :
use Barryvdh\DomPDF\Facade\Pdf;
fuck anyone else opinion
thats the only solution
$pdf = FacadePdf::loadView('admin.pdf');
return $pdf->download('order.details.pdf');
Si estas usando:
"use Barryvdh\DomPDF\Facade\Pdf;", deberás usar "Pdf::loadView()".
Si estas usando:
"use Barryvdh\DomPDF\Facade\Pdf as PDF;", podrás usar "PDF::loadView()"
Please sign in or create an account to participate in this conversation.