PHP code example of verusdev / faker-yandex-images

1. Go to this page and download the library: Download verusdev/faker-yandex-images library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

verusdev / faker-yandex-images example snippets


use Faker\Generator;
use Verusdev\FakerYandexImages\Provider\YandexImagesProvider;

$faker = app(Generator::class);
$faker->addProvider(new YandexImagesProvider($faker));

// ...в фабрике:
'photo' => $faker->yandexImage('bmw x5', ['directory' => storage_path('app/public/cars')]),

use Faker\Factory;
use Verusdev\FakerYandexImages\Provider\YandexImagesProvider;

$faker = Factory::create();
$faker->addProvider(new YandexImagesProvider($faker));

$models = ['bmw x5', 'toyota camry', 'kia sportage'];

foreach ($models as $model) {
    // 30 уникальных фото на модель (1 страница выдачи)
    $photos = $faker->yandexImages($model, 30, [
        'directory' => storage_path('app/public/cars'),
        'prefix'    => $faker->slug($model), // slug() встроен в Faker
    ]);

    foreach ($photos as $i => $photo) {
        Car::create(['name' => $model, 'photo' => basename($photo)]);
    }
}

$faker->yandexImageUrl('bmw x5');          // https://avatars.mds.yandex.net/...
$faker->yandexImageUrls('bmw x5', 5);      // массив из 5 уникальных URL