【问题标题】:Error to update laravel 5.8 to laravel 7.0将 laravel 5.8 更新到 laravel 7.0 时出错
【发布时间】:2020-03-09 21:41:27
【问题描述】:
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);
    }
}

【问题讨论】:

  • 这里有每个版本的升级指南:laravel.com/docs/6.x/upgrade。必须看看它们。在运行应用程序之前,您将消除大部分错误。

标签: php laravel laravel-7


【解决方案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 中报告、渲染、shouldReport 和 应用程序的 App\Exceptions\Handler 的 renderForConsole 方法 类应该接受 Throwable 接口的实例而不是 异常实例。

use Throwable;

public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 2020-03-08
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 2020-05-11
    • 2020-05-10
    相关资源
    最近更新 更多