dimanche 7 février 2016

Laravel seeder sets first record with ID 2

I am trying to seed my database via DatabaseSeeder Laravel, but when it seeds the database, the first row has ID 2 instead of 1.

DatabaseSeeder.php

public function run()
{

    foreach ($this->to_truncate as $table) {
        DB::table($table)->truncate();
    }

  $this->call('UsersTableSeeder');
}

UsersTableSeeder.php

use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
{
    public function run()
    {
        factory('App\User', 1)->create();
    }
}

ModelFactory.php

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'full_name' => 'Jakub Kohout',
        'username' => 'Admin',
        'email' => 'test@gmail.com',
        'password' => bcrypt('Uchiha'),
        'role_id' => 1
    ];
});

My seeding process looks like this:

heroku run php artisan migrate
heroku run php artisan db:seed

This is the migration for my User model:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('username');
        $table->string('email')->unique();
        $table->string('full_name');
        $table->integer('role_id')->unsigned();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire