29 lines
756 B
PHP
29 lines
756 B
PHP
<?php
|
|
|
|
namespace App\Commands\Account;
|
|
|
|
use App\Commands\Command;
|
|
use App\Models\Balance;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateBalanceCommand implements Command
|
|
{
|
|
public function execute(array $data): mixed
|
|
{
|
|
return DB::transaction(
|
|
callback: fn () => Balance::query()->updateOrCreate(
|
|
[
|
|
'id' => $data['id'] ?? null,
|
|
'account_id' => $data['account_id'],
|
|
'is_starting' => isset($data['starting_balance']),
|
|
'branch_id' => $data['branch_id'] ?? null,
|
|
],
|
|
[
|
|
'balance' => $data['starting_balance'],
|
|
]
|
|
),
|
|
attempts: 2
|
|
);
|
|
}
|
|
}
|