James Cole
2022-03-19 07:34:09 +01:00
parent e3ecfdfac6
commit 55a6cc5cd4
3 changed files with 74 additions and 23 deletions

View File

@@ -43,6 +43,15 @@ class TransactionCurrencyFactory
*/
public function create(array $data): TransactionCurrency
{
// if the code already exists (deleted)
// force delete it and then create the transaction:
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
if(1 === $count) {
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
$old->forceDelete();
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
}
try {
/** @var TransactionCurrency $result */
$result = TransactionCurrency::create(