0
votes

I'm new to Laravel, When I run php artisan db:seed i recieve the following message:

[ReflectionException] Class DatabaseSeeder does not exist

I already have run composer dump-autoload sadly without any result. My class is located in the default folder /seeds

The code from the class:

<?php namespace database\seeds;

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Country; 

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call('CountryTableSeeder');
        $this->call('UserTableSeeder');
    }


}

class UserTableSeeder extends Seeder {

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

        User::Create(['username' => 'Bart', 'email'=>'[email protected]', 'password' => Hash::make('password')]); 
    }
}

class CountryTableSeeder extends Seeder { 
    public function run() {
        DB::table('country');

        Country::Create(['country_name' => 'Nederlander']);
    }
}

What I'm doing wrong?

2
Take out the namespace database\seeds; at the topJoeCoder

2 Answers

4
votes

First you should remove namespace database\seeds;as @JoeCoder suggested in comment.

And the second thing is that you should not put many classes inside one file (as you probably did looking at your question). Each class should be placed in separate file.

0
votes

if you've tried everything else and still getting Class DatabaseSeeder does not exist, take a look at your composer.json

There should be a section that looks something like:

    "autoload": {
        "classmap": [
            "app/Library",
            "app/Models"
        ],
...

You should add two more lines here to tell autoloader where else it should look for your classes.

So final result will be:

    "autoload": {
        "classmap": [
            "app/Library",
            "app/Models",
            "database/seeds",
            "database/migrations"
        ],
...

This will add both seeds and migrations directory to your autoloader class path.