2015-11-17 19:45

致命错误:在第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": [
        "psr-4": {
            "App\\": "app/"
    "autoload-dev": {
        "classmap": [
    "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


  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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongwen1909 dongwen1909 6年前

    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.

    点赞 评论 复制链接分享