1
PHP Fatal error: Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in /Users/yasmin/projects/laravel/idtrue-laravel/app/Exceptions/Handler.php on line 8

当我尝试将Laravel 5.8更新为Laravel 7.0时出现此错误,已解决将App\Exceptions\Handler.php更新为:

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
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  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
    public function render($request, Throwable $exception)
    {
        return parent::render($request, $exception);
    }
}
4

1 回答 1

1

要将 laravel 5.8 升级到 laravel 7,建议先按照 laravel 6 升级指南升级到 laravel 6,检查是否正常运行,然后再升级到 laravel 7。

要将 laravel 6 升级到 7,您应该遵循升级指南,您提到的解决方案已经在 laravel 升级指南中描述:laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades。

其中说:

在 App\Exceptions\Handler.php 中,应用程序的 App\Exceptions\Handler 类的 render、shouldReport 和 renderForConsole 方法应该接受 Throwable 接口的实例而不是 Exception 实例。

use Throwable;

public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);
于 2020-04-08T13:47:04.063 回答