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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划