Laravel 5.1到5.2升级错误

Laravel 5.1 to 5.2 upgrade error

当我尝试使用官方指南将我们现有的项目从 Laravel 5.1 更新到 Laravel 5.2 时,当 post 更新

时,我在作曲家更新后收到错误消息

php artisan clear-compiled

是运行。这是错误。

Class Illuminate\Foundation\Composer does not exist

有没有人遇到过类似的问题?当我 运行 composer update with the no scripts flag 时,它会定期更新,所以这是一个清晰编译的问题。

下面是我的服务提供商和我的 composer.json 文件。

服务提供商

    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    // Illuminate\Redis\RedisServiceProvider::class,
    Vetruvet\PhpRedis\PhpRedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    Collective\Html\HtmlServiceProvider::class,
    Laravel\Socialite\SocialiteServiceProvider::class,
    Intervention\Image\ImageServiceProvider::class,
    Torann\GeoIP\GeoIPServiceProvider::class,
    Jenssegers\Agent\AgentServiceProvider::class,
    Barryvdh\Debugbar\ServiceProvider::class,

composer.json

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "fzaninotto/faker": "^1.6@dev",
    "laravelcollective/html": "5.2.*",
    "laravelcollective/remote": "~5.2",
    "kriswallsmith/assetic": "^1.3@dev",
    "pda/pheanstalk": "^3.0@dev",
    "aws/aws-sdk-php-laravel": "~3.0",
    "illuminate/http": "~5.2",
    "illuminate/session": "~5.2",
    "illuminate/support": "~5.2",
    "nesbot/carbon": "~1.18",
    "guzzlehttp/guzzle": "~5.3|~6.0",
    "vetruvet/laravel-phpredis": "dev-master",
    "predis/predis": "^1.1@dev",
    "laravel/socialite": "^3.0@dev",
    "intervention/image": "^2.3@dev",
    "brightcove/api": "^1.0@dev",
    "torann/geoip": "dev-master",
    "graham-campbell/throttle": "~5.1",
    "jenssegers/agent": "^3.0@dev"
},
"require-dev": {
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1",
    "symfony/dom-crawler": "~3.0",
    "symfony/css-selector": "~3.0",
    "barryvdh/laravel-debugbar": "^2.0@dev",
    "laracasts/generators": "dev-master"
},
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/nardev/laravel-vzaar.git"
    }
],
"autoload": {
    "classmap": [
        "database",
        "app/Models",
        "app/Footgoll"
    ],
    "files": [
        "app/helpers.php"
    ],
    "psr-4": {
        "Myapp\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}

当我运行

grep -nH -d recurse 'Composer' bootstrap/ app/ config/

这是返回的内容:

bootstrap/autoload.php:7:| Register The Composer Auto Loader bootstrap/autoload.php:10:| Composer provides a convenient, automatically generated class loader bootstrap/autoload.php:42:| when working locally. However we will need to load in the Composer

这是 autoload.php 文件的样子:

    <?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/cache/compiled.php';

if (file_exists($compiledPath)) {
    require $compiledPath;
}

/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench'))
{
    Xtwoend\Workbench\Starter::start($workbench);
}

会不会是关于 workbench 的事情?

更新:将 Composer.php 从 5.1 返回到 vendor/laravel/framework/src/Illuminate/Foundation 的一个非常可怕的修复让应用程序正常运行,但我真的需要一个更好的解决方案,一个可以推向生产的解决方案。

尝试

php artisan optimize --force

如果错误继续删除 vendor/compiled.php 然后 运行 上面的命令 这将重新创建 vendor/compiled.php class.

上面的命令删除了两个文件

The bootstrap/compiled.php file. This file is created when you optimize classes. The app/storage/meta/services.json file. This file is created as Laravel tries to optimize the loading of the service providers your application uses.

Source

当我 运行 清除编译时,它删除了我项目中的 vendor/compiled。php。

因为你根本没有编译 class 你不能删除它。这一定是您遇到问题的原因。不要打扰清除已编译的 classes..

我也正在将一个巨大的应用程序从 4.2 升级到 5.0。问题问题.. :)

正在此处识别和讨论错误:

https://github.com/laravel/framework/issues/9678

可能是SocialiteServiceProvider,也可能是其他的。

我昨晚升级的时候遇到了这个问题,很多服务提供商也要把他们的代码升级到5.2。

AdamWathan\EloquentOAuthL5\Installation好像是直接使用Composerclass,去掉这个服务提供者就可以继续升级了

好吧,我刚刚用 5.2 制作了一个新的 laravel 应用程序并再次添加了所有代码和依赖项,现在似乎可以正常工作了。

你得到的错误都是关于你使用的包。由于Composerclass位置发生变化,定位失败

来自升级笔记:

The Illuminate\Foundation\Support\Composer class has been moved to Illuminate\Support\Composer.

等待拉取请求被接受,例如 composer.json 文件中包含的 laracasts/generators 包是与 [=32] 不兼容的包之一=]

https://github.com/laracasts/Laravel-5-Generators-Extended/issues/81

因此,发生此错误的最常用包之一是 cviebrock/eloquent-sluggable

https://github.com/cviebrock/eloquent-sluggable/issues/214.

除了等待拉取请求被接受或只是编辑供应商文件之外,您别无他法,这不是一个很酷的选择。

试试这个:

composer update --no-scripts

它让我看到了 composer update 失败原因的详细解释。对我来说,我正在更新到 laravel 5.2 但忘记也将 "laravelcollective/html": "5.1.*" 更新到 "laravelcollective/html": "5.2.*"

在此处找到