'PHP errors after installing Dompdf in Laravel
I ran this:
composer require barryvdh/laravel-dompdf
Then I registered in bootstrap/app.php:
$app->register(\Barryvdh\DomPDF\ServiceProvider::class);
Then I tried to publish:
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider".
Then i got big error which bellow:
PHP Fatal error: Uncaught ReflectionException: Class config does not exist in G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
Stack trace:
#0 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(809): ReflectionClass->__construct('config')
#1 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container->build('config')
#2 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(796): Illuminate\Container\Container->resolve('config', Array, true)
#3 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(637): Illuminate\Foundation\Application->resolve('config', Array)
#4 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(781): Illuminate\Container\Container->make('config', Array)
#5 G:\web dev in G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 811
Fatal error: Uncaught ReflectionException: Class config does not exist in G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
Stack trace:
#0 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(809): ReflectionClass->__construct('config')
#1 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container->build('config')
#2 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(796): Illuminate\Container\Container->resolve('config', Array, true)
#3 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php(637): Illuminate\Foundation\Application->resolve('config', Array)
#4 G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(781): Illuminate\Container\Container->make('config', Array)
#5 G:\web dev in G:\web development all classes\simba2\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 811.
Now when I try to run php artisan ser this, it shows me the same error.
Solution 1:[1]
I think registering laravel-dompdf in bootstrap/app.php is meant for lumen not for laravel.
What you need to do is :
first remove this line
$app->register(\Barryvdh\DomPDF\ServiceProvider::class);from yourbootstrap/app.phpOpen
config/app.phpfile and incorporate DomPDF service provider in providers array along with DomPDF facade to the aliases array like so :Add
Barryvdh\DomPDF\ServiceProvider::class,to theprovidersarray like below :'providers' => [ /* * Laravel Framework Service Providers... */ Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Illuminate\Bus\BusServiceProvider::class, Illuminate\Cache\CacheServiceProvider::class, ... /* * Package Service Providers... */ Barryvdh\DomPDF\ServiceProvider::class, // added here /* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, ... ],Add
'PDF' => Barryvdh\DomPDF\Facade::class,to thealiasesarray like below :'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Arr' => Illuminate\Support\Arr::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, ... ... 'PDF' => Barryvdh\DomPDF\Facade::class, ],Save your
config/app.php
Finally Execute the following command to publish the assets from vendor.
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
This should solve your issue
You can start using laravel-dompdf :
use PDF;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
