1
I am currently working with models, Migrations, Seeds and fakers (Factory) for database testing.
So far I’m ordering to insert 1 admin, whose code I present:
DB::table('users')->insert([
'id'=>'1',
'name' => 'admin',
'email' => '[email protected]',
'password' => bcrypt('admin'),
'remember_token' => str_random(10),
]);
}}
My problem is that when I do command php artisan db:seed
the second time it gives me an error that the id of users already has value of 1 and it is not possible to insert more.
I know it is possible to check in User models if there is already an id equal or not.
What I need is even that in the User models check if there is already 1 admin if it exists it does not insert user but inserts the rest of the Migrations.
I leave here the properties of the User model
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
Thanks Anderson Carlos Woss worked perfectly
– Vitor