PHP code example of zpmlabs / undraw-php

1. Go to this page and download the library: Download zpmlabs/undraw-php 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/ */

    

zpmlabs / undraw-php example snippets


use Undraw\Factory\UndrawFactory;

$client = UndrawFactory::create(); // in-memory cache by default

$results = $client->search('music', 10); // array of Undraw\DTO\Illustration

foreach ($results as $i) {
    echo $i->title . ' => ' . $i->mediaUrl . PHP_EOL;
    $svg = $client->getSvg($i); // raw SVG string
}

use Undraw\Factory\UndrawFactory;
use Undraw\UndrawClient;
use Undraw\Support\Laravel\LaravelCacheAdapter;

app()->bind(UndrawClient::class, function () {
    return UndrawFactory::create(new LaravelCacheAdapter());
});

    Select::make('undraw_media')
        ->searchable()
        ->getSearchResultsUsing(function (string $search) {
            /** @var \Undraw\UndrawClient $u */
            $u = app(\Undraw\UndrawClient::class);
            return collect($u->search($search, 20))
                ->mapWithKeys(fn($i) => [$i->mediaUrl => $i->title])
                ->all();
        })
        ->hint('Search undraw…');