Shohid khan
Shohid khan

Reputation: 21

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.

Upvotes: 2

Views: 1485

Answers (1)

WaLid LamRaoui
WaLid LamRaoui

Reputation: 2465

I think registering laravel-dompdf in bootstrap/app.php is meant for lumen not for laravel.

What you need to do is :

  1. first remove this line $app->register(\Barryvdh\DomPDF\ServiceProvider::class); from your bootstrap/app.php

  2. Open config/app.php file and incorporate DomPDF service provider in providers array along with DomPDF facade to the aliases array like so :

    • Add Barryvdh\DomPDF\ServiceProvider::class, to the providers array 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 the aliases array 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

  3. 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;

Upvotes: 2

Related Questions