Skip to content

ZPMLabs/undraw-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

undraw-php

Lightweight client for undraw.co search (using Next.js data routes).
Returns typed DTOs and lets you fetch SVG code.

Install

composer require ZPMLabs/undraw-php
# You also need a PSR-18 client & PSR-17 factories (Discovery will find them).
# Example:
composer require guzzlehttp/guzzle nyholm/psr7

Usage

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
}

With Laravel

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

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

With Filament

    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…');

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages