*/ class AccountBalanceFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'account_id' => Account::factory(), 'balance_date' => fake()->date(), 'balance' => fake()->numberBetween(100000, 10000000), ]; } /** * Indicate that the balance has an invested amount. */ public function withInvestedAmount(?int $investedAmount = null): static { return $this->state(fn (array $attributes) => [ 'invested_amount' => $investedAmount ?? fake()->numberBetween( (int) ($attributes['balance'] * 0.5), $attributes['balance'] ), ]); } }