skip to Main Content

I just tried to upgrade Laravel from v6 to v7, my php version is 7.3, i upgraded all dependencies as stated on laravel site, and removed conflicting packages, the upgrade seems to be completed but with the following error:

Generating optimized autoload files> IlluminateFoundationComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error:  Declaration of AppExceptionsHandler::report(Exception $exception) must be compatible with IlluminateFoundationExceptionsHandler::report(Throwable $e) in /var/www/html/virtuozzo-api/app/Exceptions/Handler.php on line 8
PHP Fatal error:  Uncaught ReflectionException: Class AppExceptionsHandler does not exist in /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
Stack trace:
#0 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(803): ReflectionClass->__construct('App\Exceptions\...')
#1 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(681): IlluminateContainerContainer->build('App\Exceptions\...')
#2 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(787): IlluminateContainerContainer->resolve('App\Exceptions\...', Array, false)
#3 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(265): IlluminateFoundationApplication->resolve('App\Exceptions\...', Array, false)
#4 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): IlluminateContainerContainer->IlluminateContainer{cl in /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 805
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

i have tried already deleting the vendor folder and installing again, also with composer dump autoload, and tried to clear laravel cache, but always get the same error.

2

Answers


  1. In your app/Exceptions/Handler.php file: replace the Exception typehints with Throwable typehints.

    As mentioned in the Upgrade guide.

    Login or Signup to reply.
  2. Here is the difference

    Laravel 7 app > Exception > Handler.php

    Here is the updated file,

    <?php
    
    namespace AppExceptions;
    
    use Exception;
    use IlluminateFoundationExceptionsHandler as ExceptionHandler;
    use IlluminateHttpRequest;
    use SymfonyComponentHttpFoundationResponse;
    use Throwable;
    
    class Handler extends ExceptionHandler
    {
        /**
         * A list of the exception types that are not reported.
         *
         * @var array
         */
        protected $dontReport = [
            //
        ];
    
        /**
         * A list of the inputs that are never flashed for validation exceptions.
         *
         * @var array
         */
        protected $dontFlash = [
            'password',
            'password_confirmation',
        ];
    
        /**
         * Report or log an exception.
         *
         * @param Throwable $exception
         * @return void
         *
         * @throws Exception
         */
        public function report(Throwable $exception)
        {
            parent::report($exception);
        }
    
        /**
         * Render an exception into an HTTP response.
         *
         * @param Request $request
         * @param Throwable $exception
         * @return Response
         *
         * @throws Throwable
         */
        public function render($request, Throwable $exception)
        {
            return parent::render($request, $exception);
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search