App\Services\Medialibrary\MediaLibraryEventHandler::whenMediaHasBeenAdded PHP Method

whenMediaHasBeenAdded() public method

public whenMediaHasBeenAdded ( MediaHasBeenAdded $event )
$event Spatie\MediaLibrary\Events\MediaHasBeenAdded
    public function whenMediaHasBeenAdded(MediaHasBeenAdded $event)
    {
        $media = $event->media;
        $dominantColor = ColorThief::getColor($media->getPath());
        $hexColor = (new Rgb(...$dominantColor))->toHex();
        $media->setCustomProperty('dominantColor', $hexColor);
        $media->save();
    }
MediaLibraryEventHandler