Laravel 7 从 laravel 6 升级时抛出错误 255
Laravel 7 throws error 255 upgrading from laravel 6
我刚刚尝试将 Laravel 从 v6 升级到 v7,我的 php 版本是 7.3,我按照 laravel 站点上的说明升级了所有依赖项,并删除了冲突的包,升级似乎已完成,但出现以下错误:
Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error: Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in /var/www/html/virtuozzo-api/app/Exceptions/Handler.php on line 8
PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler 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): Illuminate\Container\Container->build('App\Exceptions\...')
#2 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(787): Illuminate\Container\Container->resolve('App\Exceptions\...', Array, false)
#3 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(265): Illuminate\Foundation\Application->resolve('App\Exceptions\...', Array, false)
#4 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): Illuminate\Container\Container->Illuminate\Container\{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
我已经尝试删除 vendor 文件夹并重新安装,也尝试使用 composer dump autoload,并尝试清除 laravel 缓存,但总是出现相同的错误。
在您的 app/Exceptions/Handler.php
文件中:将 Exception
类型提示替换为 Throwable
类型提示。
如Upgrade guide所述。
这是不同之处
这是更新后的文件,
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
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);
}
}
我刚刚尝试将 Laravel 从 v6 升级到 v7,我的 php 版本是 7.3,我按照 laravel 站点上的说明升级了所有依赖项,并删除了冲突的包,升级似乎已完成,但出现以下错误:
Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error: Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in /var/www/html/virtuozzo-api/app/Exceptions/Handler.php on line 8
PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler 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): Illuminate\Container\Container->build('App\Exceptions\...')
#2 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(787): Illuminate\Container\Container->resolve('App\Exceptions\...', Array, false)
#3 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(265): Illuminate\Foundation\Application->resolve('App\Exceptions\...', Array, false)
#4 /var/www/html/virtuozzo-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): Illuminate\Container\Container->Illuminate\Container\{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
我已经尝试删除 vendor 文件夹并重新安装,也尝试使用 composer dump autoload,并尝试清除 laravel 缓存,但总是出现相同的错误。
在您的 app/Exceptions/Handler.php
文件中:将 Exception
类型提示替换为 Throwable
类型提示。
如Upgrade guide所述。
这是不同之处
这是更新后的文件,
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
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);
}
}