6

I am following the tutorial in "Laravel 5 Essentials." When I try to seed my database with the command

php artisan db:seed

I receive the error

[ReflectionException]
  Class BreedsTableSeeder does not exist

The code for BreedsTableSeeder is defined below:

<?

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

class BreedsTableSeeder extends Seeder {

    public function run() 
    {
        DB:table('breeds')->insert([
        ['id' => 1, 'name' => "Domestic"],
        ['id' => 2, 'name' => "Persian"],
        ['id' => 3, 'name' => "Siamese"],
        ['id' => 4, 'name' => "Abyssinian"],
        ]);
    }
}

The DatabaseSeeder is defined as such:

<?php

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

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

        // $this->call(UserTableSeeder::class);
        $this->call('BreedsTableSeeder');
    }
}

1 I noticed that "DB" has a different color when I load sample code in Sublime, which makes me suspect that this has something to do with the DB namespace. Because I am new to Laravel, I am not sure where DB should be defined.

I also tried executing

composer dump-autoload

but that did not work. Does anyone know how to fix this problem? Thanks!

jstein
  • 633
  • 1
  • 8
  • 14

3 Answers3

6

Try:

php artisan make:seeder BreedsTableSeeder

Details can be found - Laravel seeding

  • After deleting the Seeder and running Laravel's built in command, `php artisan db:seed` executed without any errors. What does `php artisan make:seeder` do that I wasn't doing by manually creating a seeder file? – jstein Sep 04 '15 at 20:11
  • I had the same error, and I dont know why, but the migrations just work when you make it through artisan – Miharbi Hernandez Sep 05 '15 at 01:17
  • The reason for this is that it makes the file and then runs composer dump-autoload. – Bill Garrison Jun 21 '16 at 20:27
0

A couple things :

  1. It sounds like your seeder class didn't get added to the classmap for some reason. The place to check is the /vendor/composer/autoload_classmap.php file. If you see your class in there, it should work. If you don't, then a name change or something else went wrong at some point and you may need to add it manually.

  2. You will need to add the namespace for the DB class. It should be :

    use Illuminate\Support\Facades\DB;

Jimmy Zoto
  • 1,703
  • 2
  • 17
  • 19
  • Thank you for the quick feedback. I checked autoload_classmap.php but the class was listed. I also added the "use Illuminate\Support\Facades\DB" and I am still having the same error. – jstein Sep 02 '15 at 21:18
  • I think you need to fully qualify the name of BreedsTableSeeder. It should probably be : $this->call('database\seeds\BreedsTableSeeder'). – Jimmy Zoto Sep 02 '15 at 21:31
0

You just need to add use Illuminate\Support\Facades\DB; to the top of your BreedsTableSeeder file.

Ema4rl
  • 577
  • 1
  • 6
  • 17
Mudasir Bhat
  • 51
  • 1
  • 2