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 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了