Laravel Seed - 不工作

时间:2013-09-23 13:01:28

标签: laravel laravel-4

我正按照此处的说明尝试播种我的数据库: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'));
    }

}

2 个答案:

答案 0 :(得分:1)

这不是Laravel的问题,只是Laravel无法使用Monolog,因为作曲家没有自动加载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!";
}

答案 1 :(得分:1)

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

composer self-update

这帮助了我,dump-autoload和更新后的工作。