0

我最近将项目中的 Laravel 从 5.8.* 升级到了 6.x 版本。

现在,当我尝试运行 command 时composer dump-autoload -o,出现此错误:

Declaration of App\Exceptions\Handler::renderHttpException(Symfony\Component\HttpKernel\Exception\HttpException $e)
   should be compatible with Illuminate\Foundation\Exceptions\Handler::renderHttpException(Symfony\Component\HttpKern
  el\Exception\HttpExceptionInterface $e)

下面是composer.json项目中的设置,当我将 Laravel 从 5.7.* 升级到 5.8.* 时,我也遇到了与上面相同的错误,但我进一步升级希望能解决问题:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "repositories": [
        {
        "type": "composer",
        "url": "https://packages.[company_api].com"
        }
    ],
    "require": {
        "php": ">=7.1.3",
        "basemkhirat/elasticsearch": "^1.3",
        "botman/botman": "^2.5",
        "botman/driver-web": "^1.5",
        "deployer/deployer": "^6.0",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.3",
        "jenssegers/agent": "^2.6",
        "jimmiw/php-time-ago": "^2.0",
        "laravel/framework": "^6.0",
        "laravel/scout": "^8.0",
        "laravel/tinker": "~1.0",
        "[company_name]/wordpressblogapi": "1.4.*"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        },
      "files": [
        "helpers/helpers.php"
      ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },

    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

我已经参考了文档,它没有具体说明任何ExceptionHandler.php文件更改,所以任何人都建议如何解决这个问题......

4

1 回答 1

1

这是 5.7 到 5.8 的升级问题,正如您在问题开始时指出的那样。该方法的签名发生了变化:

“类的renderHttpException方法签名Illuminate\Foundation\Exceptions\Handler已更改。如果您在异常处理程序中覆盖此方法,则应更新方法签名以匹配其父项:”

/**
 * Render the given HttpException.
 *
 * @param  \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface  $e
 * @return \Symfony\Component\HttpFoundation\Response
 */
protected function renderHttpException(HttpExceptionInterface $e);

Laravel 5.8 文档 - 升级指南 - 异常处理

于 2020-06-20T02:37:26.393 回答