Laravel Image Faker is an alternative image provider for FakerPHP.
composer require alirezasedghi/laravel-image-faker
The following sources are utilized by this project to create random images:
- Lorem Picsum
- LoremFlickr
- PlaceDog
- Kittens (Random Cats) by TheOldReader.com
- Fake People by BoredHumans.com
Code | Description |
---|---|
(new ImageFaker(new Service()))->imageUrl() |
Return a random image url from the specified service |
(new ImageFaker(new Service()))->image() |
Download a random image from the specified service |
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
/**
* In order to utilize other services, the following substitutes can be used:
* - new ImageFaker(new LoremFlickr());
* - new ImageFaker(new PlaceDog());
* - new ImageFaker(new Kittens());
* - new ImageFaker(new FakePeople());
*/
$imageFaker = new ImageFaker(new Picsum());
return [
'title' => $this->faker->sentence(),
'content' => $this->faker->paragraph(),
'attachments' => $imageFaker->image( storage_path("app/attachments/") )
];
}
Don't hesitate to send a PR if you're looking for a service that's not available in this package. 😁
The MIT License (MIT). Please see License File for more information.