horcrux88
horcrux88

Reputation: 331

Laravel DB Seeder won't seed in console

Hi I have the following seeder class I am trying to seed. When I run the php artisan db:seed command the only thing that seeds is my previous seeder class I created a few weeks ago. I have no idea what I am missing. I inserted SoftDeletes and Protected fillables as well.

Here is my seeder class:

    public function run()
{
    DB::table('leave_type')->insert([
      [
        'leaveType' => 'Vacation Leave'
      ],
      [
        'leaveType' => 'Sick Leave'
      ],
      [
        'leaveType' => 'Afternoon Off'
      ],
      [
        'leaveType' => 'Special Leave'
      ],
      [
        'leaveType' => 'Study Leave'
      ],
    ]);
}

My model:

    namespace App;

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\SoftDeletes;

    class LeaveType extends Model
     {
       protected $fillable = ['leaveType'];
       protected $table ="leave_type";
       use SoftDeletes;
       public $timestamps = true;
    }

Upvotes: 1

Views: 2811

Answers (1)

Latheesan
Latheesan

Reputation: 24116

Converting my comment to answer;

  1. Make sure laravel knows about the new database seeder class you've generated by running this command:

composer dump-auto

  1. Make sure your seeder class is registered in {PROJECT}/database/seeds/DatabaseSeeder.php like this:

$this->call(YourNewSeeder::class);

Then you could refresh the database (rollback all migration, re-run the migration) and run the seeder in one go with this command:

php artisan migrate:refresh --seed

or just run the specific seeder only like this:

php artisan db:seed --class=YourNewSeeder

Upvotes: 4

Related Questions