I'm trying to use the barryvdh/laravel-dompdf package in my Laravel project. After installing it via Composer, I followed the official documentation and added the provider and alias manually in my config/app.php file like this:
'providers' => ServiceProvider::defaultProviders()->merge([
Barryvdh\DomPDF\ServiceProvider::class,
]),
'aliases' => Facade::defaultAliases()->merge([
'PDF' => Barryvdh\DomPDF\Facade::class,
]),
However, I am getting the following error:
Undefined type 'Barryvdh\DomPDF\Facade'
I have verified that the package is installed successfully by checking my composer.json and running composer show barryvdh/laravel-dompdf.
Here is what I have tried so far:
Ran composer dump-autoload
Cleared config cache using php artisan config:clear
Tried importing the facade directly in the file where I use it.
Instead of
'PDF' => Barryvdh\DomPDF\Facade::class,
use
'PDF' => Barryvdh\DomPDF\Facade\Pdf::class,
inside your controller:
use Illuminate\Support\Facades\File;
$pdf = Pdf::loadView('pdf_view', $data);