PDF class not found in dompdf library

Viewed 1481
use Illuminate\Http\Request;
use PDF;
  
class PDFController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function generatePDF()
    {
        $data = [
            'title' => 'hello world',
            'date' => date('m/d/Y')
        ];
          
        $pdf = PDF::loadView('myPDF', $data);
    
        return $pdf->download('itsolutionstuff.pdf');
    }
}
2 Answers

Step 1:-

composer require barryvdh/laravel-dompdf

step-2:-

In ..\config\app.php

'providers' => [ 
  Barryvdh\DomPDF\ServiceProvider::class,
],
'aliases' => [
 'PDF' => Barryvdh\DomPDF\Facade::class,
]

step 3:-

use \PDF;

Step 4:-

$pdf = PDF::loadView('pdf.file_name');
return $pdf->stream('file_name.pdf', array('Attachment' => 0));

Step 5:-

php artisan cache:clear
// and
php artisan config:cache

just in case anyone still looks at this i needed composer require barryvdh/laravel-dompdf --dev

An easy miss i guess..

Related