PHP Trait Spatie\MediaLibrary\HasMedia\HasMediaTrait

Show file Open project: spatie/laravel-medialibrary

Public Properties

Property Type Description
$mediaConversions array

Protected Properties

Property Type Description
$deletePreservingMedia boolean

Public Methods

Method Description
addMedia ( string | Symfony\Component\HttpFoundation\File\UploadedFile $file ) : FileAdder Add a file to the medialibrary.
addMediaConversion ( string $name ) : Conversion * Add a conversion.
addMediaFromRequest ( string $key ) : FileAdder Add a file from a request.
addMediaFromUrl ( string $url ) : FileAdder Add a remote file to the medialibrary.
bootHasMediaTrait ( )
clearMediaCollection ( string $collectionName = 'default' ) Remove all media in the given collection.
copyMedia ( string | Symfony\Component\HttpFoundation\File\UploadedFile $file ) : FileAdder Copy a file to the medialibrary.
deleteMedia ( integer | Media $mediaId ) Delete the associated media with the given id.
deletePreservingMedia ( ) : boolean Delete the model, but preserve all the associated media.
getFirstMedia ( string $collectionName = 'default', array $filters = [] ) : Media | null Get the first media item of a media collection.
getFirstMediaPath ( string $collectionName = 'default', string $conversionName = '' ) : string * Get the url of the image for the given conversionName for first media for the given collectionName.
getFirstMediaUrl ( string $collectionName = 'default', string $conversionName = '' ) : string * Get the url of the image for the given conversionName for first media for the given collectionName.
getMedia ( string $collectionName = '', $filters = [] ) : Collection * Get media collection by its collectionName.
hasMedia ( string $collectionName = '' ) : boolean * Determine if there is media in the given collection.
media ( ) : mixed Set the polymorphic relation.
shouldDeletePreservingMedia ( ) : Media Determines if the media files should be preserved when the media object gets deleted.
updateMedia ( array $newMediaArray, string $collectionName = 'default' ) : array Update a media collection by deleting and inserting again with new values.

Protected Methods

Method Description
removeMediaItemsNotPresentInArray ( array $newMediaArray, string $collectionName = 'default' )

Method Details

addMedia() public method

Add a file to the medialibrary.
public addMedia ( string | Symfony\Component\HttpFoundation\File\UploadedFile $file ) : FileAdder
$file string | Symfony\Component\HttpFoundation\File\UploadedFile
return Spatie\MediaLibrary\FileAdder\FileAdder

addMediaConversion() public method

* Add a conversion.
public addMediaConversion ( string $name ) : Conversion
$name string
return Spatie\MediaLibrary\Conversion\Conversion

addMediaFromRequest() public method

Add a file from a request.
public addMediaFromRequest ( string $key ) : FileAdder
$key string
return Spatie\MediaLibrary\FileAdder\FileAdder

addMediaFromUrl() public method

Add a remote file to the medialibrary.
public addMediaFromUrl ( string $url ) : FileAdder
$url string
return Spatie\MediaLibrary\FileAdder\FileAdder

bootHasMediaTrait() public static method

public static bootHasMediaTrait ( )

clearMediaCollection() public method

Remove all media in the given collection.
public clearMediaCollection ( string $collectionName = 'default' )
$collectionName string

copyMedia() public method

Copy a file to the medialibrary.
public copyMedia ( string | Symfony\Component\HttpFoundation\File\UploadedFile $file ) : FileAdder
$file string | Symfony\Component\HttpFoundation\File\UploadedFile
return Spatie\MediaLibrary\FileAdder\FileAdder

deleteMedia() public method

You may also pass a media object.
public deleteMedia ( integer | Media $mediaId )
$mediaId integer | Spatie\MediaLibrary\Media

deletePreservingMedia() public method

Delete the model, but preserve all the associated media.
public deletePreservingMedia ( ) : boolean
return boolean

getFirstMedia() public method

Get the first media item of a media collection.
public getFirstMedia ( string $collectionName = 'default', array $filters = [] ) : Media | null
$collectionName string
$filters array
return Spatie\MediaLibrary\Media | null

getFirstMediaPath() public method

If no profile is given, return the source's url.
public getFirstMediaPath ( string $collectionName = 'default', string $conversionName = '' ) : string
$collectionName string
$conversionName string
return string

getFirstMediaUrl() public method

If no profile is given, return the source's url.
public getFirstMediaUrl ( string $collectionName = 'default', string $conversionName = '' ) : string
$collectionName string
$conversionName string
return string

getMedia() public method

* Get media collection by its collectionName.
public getMedia ( string $collectionName = '', $filters = [] ) : Collection
$collectionName string
$filters
return Illuminate\Support\Collection

hasMedia() public method

* Determine if there is media in the given collection.
public hasMedia ( string $collectionName = '' ) : boolean
$collectionName string
return boolean

media() public method

Set the polymorphic relation.
public media ( ) : mixed
return mixed

removeMediaItemsNotPresentInArray() protected method

protected removeMediaItemsNotPresentInArray ( array $newMediaArray, string $collectionName = 'default' )
$newMediaArray array
$collectionName string

shouldDeletePreservingMedia() public method

Determines if the media files should be preserved when the media object gets deleted.
public shouldDeletePreservingMedia ( ) : Media
return Spatie\MediaLibrary\Media

updateMedia() public method

Update a media collection by deleting and inserting again with new values.
public updateMedia ( array $newMediaArray, string $collectionName = 'default' ) : array
$newMediaArray array
$collectionName string
return array

Property Details

$deletePreservingMedia protected property

protected bool $deletePreservingMedia
return boolean

$mediaConversions public property

public array $mediaConversions
return array