3

我正在尝试按照此处的说明播种我的数据库:http: //laravel.com/docs/migrations#database-seeding。但是,当我运行 artisan 命令时,出现错误:

c:\wamp\www\laravel>php artisan db:seed
PHP Fatal error:  Class 'Monolog\Logger' not found in C:\wamp\www\laravel\vendor
\laravel\framework\src\Illuminate\Log\LogServiceProvider.php on line 21
PHP Stack trace:
PHP   1. {main}() C:\wamp\www\laravel\artisan:0
PHP   2. require_once() C:\wamp\www\laravel\artisan:30
PHP   3. require() C:\wamp\www\laravel\bootstrap\start.php:61
PHP   4. Illuminate\Foundation\ProviderRepository->load() C:\wamp\www\laravel\ve
ndor\laravel\framework\src\Illuminate\Foundation\start.php:195
PHP   5. Illuminate\Foundation\Application->register() C:\wamp\www\laravel\vendo
r\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:67
PHP   6. Illuminate\Log\LogServiceProvider->register() C:\wamp\www\laravel\vendo
r\laravel\framework\src\Illuminate\Foundation\Application.php:336
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","me
ssage":"Class 'Monolog\\Logger' not found","file":"C:\\wamp\\www\\laravel\\vendo
r\\laravel\\framework\\src\\Illuminate\\Log\\LogServiceProvider.php","line":21}}

任何建议如何解决这个问题?

更新 1:

即使使用文档中的示例代码也存在错误:

class DatabaseSeeder extends Seeder {

    public function run()
    {
        $this->call('UserTableSeeder');

        $this->command->info('User table seeded!');
    }

}

class UserTableSeeder extends Seeder {

    public function run()
    {
        DB::table('users')->delete();

        User::create(array('email' => 'foo@bar.com'));
    }

}
4

2 回答 2

1

这不是 Laravel 的问题,只是 Laravel 无法使用 Monolog,因为 composer 没有自动加载 Monolog Logger。

查看 vendor/composer/autoload_namespaces.php,你必须有这一行:

'Monolog' => array($vendorDir . '/monolog/monolog/src'),

如果没有,请执行

composer dump-autoload

如果它仍然不存在,请检查您是否有供应商/独白目录并执行

composer update

或者只是删除您的供应商目录并执行

composer install

编辑:

要检查问题是否在 Laravel 中,请创建如下脚本:

<?php

include "/path.to.your.app/vendor/autoload.php";

$m = new Monolog\Logger('my');

if($m instanceof Monolog\Logger)
{
    echo "Monolog is available!";
}
else
{
    echo "Monolog is NOT available or you have another problem, check your webserver log files!";
}
于 2013-09-23T13:59:03.187 回答
1

作曲家版本可能太旧了。尝试这个:

composer self-update

这帮助了我,转储自动加载和更新在那之后工作。

于 2014-03-06T06:06:38.603 回答