Looking to hire Laravel developers? Try LaraJobs

laravel-image-faker maintained by alirezasedghi

Description
A library to generate fake images for Laravel
Last update
2023/09/02 23:41 (dev-main)
License
Downloads
24 361

Comments
comments powered by Disqus

Description

Laravel Image Faker is an alternative image provider for FakerPHP.

Installation

composer require alirezasedghi/laravel-image-faker

Resources

The following sources are utilized by this project to create random images:

Methods

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

Usage

/**
 * 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/") )
    ];
}

Contributing

Don't hesitate to send a PR if you're looking for a service that's not available in this package. 😁

License

The MIT License (MIT). Please see License File for more information.