Naltroc
Naltroc

Reputation: 1007

Database Seeder cannot find class with Laravel 5.2

When running php artisan migrate --seed, this error appears:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'CreateCharactersTable' not found. 

Here is that that class:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class CharacterSeeder extends Seeder
{
    public function run()
    {
        DB::table('characters')->delete();

        DB::table('characters')->insert([
            'user_id'   => 999,
            'name'      => 'Susan Strong',
            'race'      => 'orc',
            'class'     => 'assassin',
            'image_location'    => null,
            'combat_level'      => '0',
            'base_str'  => 6,
            'base_int'  => 4,
            'base_apt'  => 5,
            'mod_str'   => 9,
            'mod_int'   => 5,
            'mod_apt'   => 7,
            'xp_str'    => 1,
            'xp_int'    => 2,
            'xp_apt'    => 1,
            'is_bot'    => 1,
            'created_at'=> '2017-04-02 17:53:02',
            'updated_at'=> '2017-04-02 17:53:02'
        ]);



        DB::table('characters')->insert([
            'user_id'   => 4,
            'name'      => 'Chale',
            'race'      => 'elf',
            'class'     => 'scholar',
            'image_location'    => null,
            'combat_level'      => '0',
            'base_str'  => 3,
            'base_int'  => 7,
            'base_apt'  => 5,
            'mod_str'   => 6,
            'mod_int'   => 10,
            'mod_apt'   => 6,
            'xp_str'    => 1,
            'xp_int'    => 2,
            'xp_apt'    => 1,
            'is_bot'    => 1,
            'created_at'=> '2017-04-02 17:53:02',
            'updated_at'=> '2017-04-02 17:53:
    }
}

?>

and the seeder:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Database\Seeds\CharacterSeeder;
use Database\Seeds\ClassesTableSeeder;
use Database\Seeds\RacesTableSeeder;
use Database\Seeds\UserTableSeeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UserTableSeeder::class);
        $this->call(CharacterSeeder::class);
        $this->call(RacesTableSeeder::class);
        $this->call(ClassesTableSeeder::class);
    }
}

Running composer dumpautoload passes but does not remove the error. When it was only two seeders, User and Character, it ran well. Despite looking over the new seeders again and again, I cannot determine the error involved.

Any suggestions to get the seeder to run?

Thank you.

Upvotes: 0

Views: 3191

Answers (3)

Marty Staas
Marty Staas

Reputation: 411

If you manually added the seeder files you should first run composer dump-autoload. This will regenerate the autoload_classmap.php file for you, see Composer Dump-Autoload for more info.

Upvotes: 15

Jialin Peng
Jialin Peng

Reputation: 1

Class 'CreateCharactersTable' should is Migration. You need check this migration file or class exists.

if you only use seeder . you can exec php artisan db:seed

Upvotes: 0

Dwight
Dwight

Reputation: 12450

You've imported all your seeders from a namespace, but they aren't in a namespace.

use Database\Seeds\CharacterSeeder;
use Database\Seeds\ClassesTableSeeder;
use Database\Seeds\RacesTableSeeder;
use Database\Seeds\UserTableSeeder;

Just remove those lines and you should be good to go.

Upvotes: 1

Related Questions