I have this seeder class in my laravel 5.2 app :
class UserTypesTableSeeder extends Seeder
{
public function run()
{
DB::table('user_types')->insert([
[
'type' => 'patient',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'type' => 'doctor',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]
]);
}
}
Now, I want to add another record in the same seeder class. I tried using firstOrCreate() :
UserType::firstOrCreate([
'type' => 'patient',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
UserType::firstOrCreate([
'type' => 'doctor',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
UserType::firstOrCreate([
'type' => 'admin',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
but it made duplicate records and so did updateOrCreate().
So, how can I add new records to the same seeder class without duplicating records ??