2

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.

4
  • Try to remove de files in: cd bootstrap/cache/ rm -rf *.php Commented Apr 27, 2022 at 7:06
  • In this directory are the file that initializes the structure, cache directory that contains structure-generated files for performance optimization, such as files and route cache services. Commented Apr 27, 2022 at 7:07
  • 1
    Please provide enough code so others can better understand or reproduce the problem. Commented Apr 27, 2022 at 13:07
  • which version of laravel you're using ? also registering dompdf in bootstrap/app.php is for lumen not laravel Commented Apr 28, 2022 at 7:19

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.