StackOverflowNewbie
StackOverflowNewbie

Reputation: 40633

Laravel Seed - not working

I'm trying to seed my database by following the instructions here: http://laravel.com/docs/migrations#database-seeding. However, when I run the artisan command, I get an error:

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}}

Any suggestions how to fix this?

UPDATE 1:

The error exist even with the sample code from the documentation:

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' => '[email protected]'));
    }

}

Upvotes: 3

Views: 5662

Answers (2)

Nerva
Nerva

Reputation: 153

The composer version could be too old. Try this:

composer self-update

This helped me out, dump-autoload and update worked after that.

Upvotes: 1

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

This is not a Laravel problem, it's just that Laravel is unable to use Monolog, because composer didn't autoloaded Monolog Logger.

Look into vendor/composer/autoload_namespaces.php, you must have this line there:

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

If you have not, execute

composer dump-autoload

If it's still not there, check if you have a vendor/monolog dir and do a

composer update

Or just delete your vendor dir and execute

composer install

EDIT:

To check if the problem is in Laravel or not, create a script like this one:

<?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!";
}

Upvotes: 1

Related Questions