Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Seeding

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!

like image 825
jstein Avatar asked Sep 02 '15 20:09

jstein


1 Answers

Try:

php artisan make:seeder BreedsTableSeeder

Details can be found - Laravel seeding

like image 60
Miharbi Hernandez Avatar answered Nov 01 '22 01:11

Miharbi Hernandez