Spatie\MediaLibrary\Media::getUrl PHP Method

getUrl() public method

Get the original Url to a media-file.
public getUrl ( string $conversionName = '' ) : string
$conversionName string
return string
    public function getUrl(string $conversionName = '') : string
    {
        $urlGenerator = UrlGeneratorFactory::createForMedia($this);
        if ($conversionName !== '') {
            $urlGenerator->setConversion(ConversionCollection::createForMedia($this)->getByName($conversionName));
        }
        return $urlGenerator->getUrl();
    }

Usage Example

 public function transform(Media $media)
 {
     return ['id' => $media->id, 'name' => $media->name, 'collection' => $media->collection_name, 'fileName' => $media->file_name, 'customProperties' => json_encode($media->custom_properties, JSON_FORCE_OBJECT), 'orderColumn' => $media->order_column, 'thumbUrl' => strtolower($media->extension) === 'svg' ? $media->getUrl() : $media->getUrl('admin'), 'originalUrl' => $media->getUrl()];
 }
All Usage Examples Of Spatie\MediaLibrary\Media::getUrl