Chirag D.Der
Chirag D.Der

Reputation: 35

PDF class not found in dompdf library

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');
    }
}

Upvotes: 2

Views: 3894

Answers (2)

DCX
DCX

Reputation: 117

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

An easy miss i guess..

Upvotes: 0

Yudiz Solutions
Yudiz Solutions

Reputation: 4459

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

Upvotes: 2

Related Questions