AlexAzartsev / heroicon

MIT License
10 stars 6 forks source link

Get svg data to use with seeder or migragtion? #16

Open scramatte opened 1 year ago

scramatte commented 1 year ago

Hi,

I'm using your package and I've created a seeder to fill tables. Does it exists a method to get icon svg to be able to use it into migration or seeder?

Regards

AlexAzartsev commented 1 year ago

Unfortunately no, but you can write helper function in your seeder to get content of desired icon using file_get_contents, for example:

    public static function icon(string $type = 'outline', string $icon = ''): string
    {
        if ($type !== 'outline' && $type !== 'solid') {
            throw new InvalidArgumentException("Only solid or outline type accepted");
        }
        if (!empty($icon) && file_exists(resource_path("img/icons/heroicons/$type/$icon.svg"))) {
            return file_get_contents(resource_path("img/icons/heroicons/$type/$icon.svg"));
        }
        $files = glob(resource_path("img/icons/heroicons/$type") . '/*.svg');
        $file = array_rand($files);

        return file_get_contents($files[$file]);
    }

you need to use proper path for you icon set