first(); $user = User::query()->first(); if ($cashAccount === null || $user === null) { CashTransaction::factory()->count(3)->deposit()->create(); return; } $balance = (int) $cashAccount->balance; foreach (range(1, 3) as $index) { $amount = fake()->numberBetween(50_000, 500_000); $balance += $amount; CashTransaction::factory()->deposit()->create([ 'cash_account_id' => $cashAccount->id, 'created_by_id' => $user->id, 'amount' => $amount, 'balance_after' => $balance, ]); } $cashAccount->update(['balance' => $balance]); } }