Laravel Seeding Safe reseeding


Example

You may want to re-seed your database without affecting your previously created seeds. For this purpose, you can use firstOrCreate in your seeder:

EmployeeType::firstOrCreate([
    'type' => 'manager',
]);

Then you can seed the database:

php artisan db:seed

Later, if you want to add another type of employee, you can just add that new one in the same file:

EmployeeType::firstOrCreate([
    'type' => 'manager',
]);
EmployeeType::firstOrCreate([
    'type' => 'secretary',
]);

And seed your database again with no problems:

php artisan db:seed

Notice in the first call you are retrieving the record but doing nothing with it.