Laravel 7 PDF Tutorial: Generate PDF in Laravel with DOMPDF
In this tutorial, I will explain how to create laravel dompdf report. so lets start
First you need to install this composer, to open cmd from root folder then you need to install the composer.
composer require barryvdh/laravel-dompdf
Configure DomPDF Package in Laravel
Open config/app.php file and incorporate DomPDF service provider in providers array along with DomPDF facade to the aliases array.
'providers' => [
Barryvdh\DomPDF\ServiceProvider::class,
],
'aliases' => [
'PDF' => Barryvdh\DomPDF\Facade::class,
]
Routing Setup
Route::get('/invoice/{id}/pdf', 'invoice@createPDF')->name('createPDF');
into the controller page
use PDF;
function createPDF($id)
{
$ids = Crypt::decrypt($id);
$qry = 'SELECT * FROM journal WHERE j_id="'.$ids.'"' ;
$ppl = DB::select($qry);
$pdf = PDF::loadView('invoice/invoice_pdf', ['ppl' => $ppl]);
// If you want to store the generated pdf to the server then you can use the store function
// $pdf->save(storage_path().'_filename.pdf');
// Finally, you can download the file using download function
return $pdf->download('customers.pdf');
}