* @property Generator|Restaurant $faker */ class ProductNutritionalValueFactory extends Factory { /** * Define the model's default state. * * @return array * */ public function definition(): array { $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); $active = $this->faker->boolean(); return [ 'name' => $this->faker->regexify('[A-Za-z0-9]{20}'), 'image' => $this->generateImageFile(), 'description' => $this->faker->text(), 'formulations' => $this->faker->text(), 'energy_on_100gr' => $this->faker->numberBetween(0,100), 'proteins_on_100gr' => $this->faker->randomFloat(1, 20, 50), 'fats_on_100gr' => $this->faker->randomFloat(1, 20, 50), 'carbohydrates_on_100gr' => $this->faker->randomFloat(1, 20, 50), 'portion_mass_gr' => $this->faker->numberBetween(0, 100), 'energy_on_portion' => $this->faker->randomFloat(1,20,50), 'proteins_on_portion' => $this->faker->randomFloat(1,20,50), 'fats_on_portion' => $this->faker->randomFloat(1,20,50), 'carbohydrates_on_portion' => $this->faker->randomFloat(1,20,50), ]; } private function generateImageFile(string $name = 'plans'): string { $images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg']; Storage::fake($name); $imageFileKey = $this->faker->numberBetween(0, 9); $imageFilePath = 'database/assets/images/plans/' . $images[$imageFileKey]; $file = new File($imageFilePath); $fileLocalPath = Storage::putFile($name, $file, 'public'); return $fileLocalPath; } }