ogsoft-example/database/seeders/CountrySeeder.php

30 lines
691 B
PHP
Raw Normal View History

<?php
namespace Database\Seeders;
use App\Models\Country;
use Illuminate\Database\Seeder;
use Illuminate\Database\UniqueConstraintViolationException;
class CountrySeeder extends Seeder
{
private const array COUNTRIES = [
'CZ' => 'Czech Republic',
];
/**
* Run the database seeds.
*/
public function run(): void
{
foreach (static::COUNTRIES as $countryCode => $countryName) {
try {
Country::create(['country_code' => $countryCode, 'name' => $countryName]);
} catch (UniqueConstraintViolationException $e) {
// safe to ignore duplicate entries
}
}
//
}
}