laravel6升级为laravel7教程以及问题总结

Song205 次浏览0个评论2021年05月28日
laravel6升级为laravel7 Laravel7需要PHP7.2.5或以上版本。 1、更新依赖 请更新在composer.json文件中以下依赖 "require":{ "laravel/framewor

laravel6升级为laravel7

Laravel 7 需要 PHP 7.2.5 或以上版本。

1、更新依赖

请更新在 composer.json 文件中以下依赖

"require": {
        "laravel/framework": "^7.0",
        "laravel/helpers": "^1.4",
        "laravel/tinker": "^2.0"
        ...

    },
    "require-dev": {
        "facade/ignition": "^2.0",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
        ...
    },

2、执行升级

composer update

出现的错误

1、未找到monolog

- Conclusion: don't install laravel/framework v7.30.3 (conflict analysis result)
- Conclusion: don't install laravel/framework v7.30.4 (conflict analysis result)
- Conclusion: don't install monolog/monolog 2.2.0 (conflict analysis result)

出现的问题是没有安装monolog,退回原来6.0的安装monolog即可。

composer require monolog/monolog

2、app/Exceptions/Handler.php异常

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
PHP Fatal error:  Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in /private/var/www/pinlebang/app/Exceptions/Handler.php on line 15
PHP Fatal error:  Uncaught ReflectionException: Class App\Exceptions\Handler does not exist in /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php:809
Stack trace:
#0 /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php(809): ReflectionClass->__construct('App\\Exceptions\\...')
#1 /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php(691): Illuminate\Container\Container->build('App\\Exceptions\\...')
#2 /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve('App\\Exceptions\\...', Array, false)
#3 /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php(269): Illuminate\Foundation\Application->resolve('App\\Exceptions\\...', Array, false)
#4 /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->Illuminate\Container\{closure} in /private/var/www/pinlebang/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 811
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

解决办法

前往app/Exceptions/Handler.php文件,将所有Exception替换为Throwable

use Exception;
# 替换为
use Throwable;

-------------

Exception $exception
# 替换为
Throwable $exception

参考:laravel6到laravel7升级说明

请登录后评论
    当前暂无评价,快来发表您的观点吧...
    公告提示
    本站主要用于学习交流Laravel技术,分享Laravel优秀案例;同时非常欢迎大家投稿哦!如果有招聘信息也可以联系我我帮忙发布哦!