Skip creation using if statement.

This commit is contained in:
James Cole
2024-05-26 15:36:30 +02:00
parent a20622ac0c
commit 7009b444d9
8 changed files with 42 additions and 30 deletions

View File

@@ -71,10 +71,12 @@ class TransactionCurrencySeeder extends Seeder
$currencies[] = ['code' => 'HRK', 'name' => 'Croatian kuna', 'symbol' => 'kn', 'decimal_places' => 2];
foreach ($currencies as $currency) {
try {
TransactionCurrency::create($currency);
} catch (\PDOException $e) {
// @ignoreException
if(null === TransactionCurrency::where('code', $currency['code'])->first()) {
try {
TransactionCurrency::create($currency);
} catch (\PDOException $e) {
// @ignoreException
}
}
}
}