*/ class BlogPostFactory extends Factory { protected $model = BlogPost::class; /** * Define the model's default state. * * @return array */ public function definition() { $faker = \Faker\Factory::create(); $this->faker->addProvider(new Youtube($faker)); return [ 'state' => $this->faker->randomElement(['active', 'archived']), 'image' => $this->generateImageFile('blog_post'), 'description' => $this->faker->realText($this->faker->numberBetween(100, 200)), 'youtube_url' => $this->faker->youtubeRandomUri(), 'title' => $this->faker->realText($this->faker->numberBetween(10, 20)), ]; } private function generateImageFile(string $name): 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/blogPosts/' . $images[$imageFileKey]; $file = new File($imageFilePath); $fileLocalPath = Storage::putFile($name, $file, 'public'); return $fileLocalPath; } }