How to generate fake images in Laravel with Faker

Categorized as Laravel Tagged

Hello friends. Did you know that you can use faker to not only generate text values but also fake images? That’s how it’s done, see the code below:

// Get a random image from placeholder.com
$image = $this->faker->image(
  dir: storage_path('app'),
  width: 250,
  height: 250,
  fullPath: false
);

// Get random image URL from placeholder.com
$imageUrl = $this->faker->imageUrl(width: 620, height: 480);

via @justsanjit

Leave a reply

Your email address will not be published. Required fields are marked *