dst2017 2015-11-17 19:45
浏览 240
已采纳

致命错误:在第146行的...... /ProviderRepository.php中找不到类......

This sounds like a trivial mistake, but I've been unable to find the solution for hours.

I tried to use https://github.com/michaelbonds/laravel-db2 in my Laravel project, and I added it using composer.

Here's my composer.json.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "michaelb/laravel-db2": "~2.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "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"
    }
}

Here's the error:

PHP Fatal error:  Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found in /var/www/html/mysjsu/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146

and

[Symfony\Component\Debug\Exception\FatalErrorException]     
  Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found

I found a similar question before on StackOverflow, and somebody suggested that the order matters. So, here's what I did in the following order:

  1. add "michaelb/laravel-db2": "~2.0" to composer.json
  2. run php ../composer.phar update
  3. add MichaelB\Database\DB2\DB2ServiceProvider::class to the providers arary in config/app.php
  4. run php artisan migrate

Any idea on what might've been the problem?

  • 写回答

1条回答 默认 最新

  • dongwen1909 2015-11-17 23:39
    关注

    This package is a fork of cooperl/laravel-db2. The documentation is inaccurate.

    He changed the namespace to MichaelB but never tagged this as a stable version, so when you composer require his ~2.0, packagist gives you an older version with the wrong namespace.

    So when you run composer update, it runs some post-cmd scripts such as php artisan optimize which tries to pull from the config file but fails because that class doesn't exist.

    Here's how to fix it:

    1. Change composer.json to this version:

      "michaelb/laravel-db2": "dev-master"
      
    2. Run composer update --no-scripts

    Then you should be good.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答
  • ¥15 ceph初始化mon不成功 下图不报错 这个是什么元
  • ¥15 数学建模数学建模少ai
  • ¥35 这个等效电路图是什么意思?(答疑)(有没有不是chat的,我就是在chat搜不到才来问的,chat还开了VIP)(可以追加酬金)
  • ¥200 基于同花顺supermind的量化策略脚本编辑
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?