*/ class ProductFactory extends Factory { protected $model = ProductModel::class; /** * @return array */ public function definition(): array { return [ 'name' => fake()->unique()->words(2, true), 'unit' => ProductUnit::Piece->value, 'price_cents' => fake()->numberBetween(100, 10000), 'vat_rate_id' => fn (): int => VatRateModel::query()->where('is_default', true)->value('id') ?? VatRateModel::factory()->create(['is_default' => true])->id, 'is_consumer_product' => false, 'auto_hours' => 0, 'work_type_id' => null, 'is_active' => true, 'sort_order' => fake()->unique()->numberBetween(100, 100000), ]; } public function consumer(): static { return $this->state(fn (): array => ['is_consumer_product' => true]); } public function inactive(): static { return $this->state(fn (): array => ['is_active' => false]); } public function withAutoHours(float $hours = 0.25): static { return $this->state(fn (): array => [ 'auto_hours' => $hours, 'work_type_id' => WorkTypeModel::factory(), ]); } }