*/ class SellItemFactory extends Factory { protected $model = SellItem::class; #[\Override] protected function withFaker() { return class_exists(\Faker\Generator::class) ? parent::withFaker() : null; } public function definition(): array { return $this->faker !== null ? $this->definitionWithFaker() : $this->definitionStatic(); } /** * @return array */ private function definitionWithFaker(): array { return [ 'name' => fake()->words(fake()->numberBetween(1, 2), true), 'picture' => '', 'picture_alt' => fake()->sentence(), 'picture_title' => fake()->sentence(), 'price' => fake()->numberBetween(1, 100), 'arcadia_weight' => fake()->numberBetween(1, 100), 'arcadia_id' => fake()->unique()->numberBetween(100, 500), 'order' => 1, 'type' => fake()->randomElement(SellItemsType::cases()), ]; } /** * @return array */ private function definitionStatic(): array { return [ 'name' => 'Article Démo Test', 'picture' => '', 'picture_alt' => 'Image descriptive article démo', 'picture_title' => 'Titre image démo', 'price' => 29.99, 'arcadia_weight' => 500, 'arcadia_id' => 101, 'order' => 1, 'type' => SellItemsType::cases()[0] ?? 'standard', ]; } }