PHP Class Spatie\MediaLibrary\MediaRepository

Show file Open project: spatie/laravel-medialibrary Class Usage Examples

Protected Properties

Property Type Description
$model Media

Public Methods

Method Description
__construct ( Media $model )
all ( ) : Illuminate\Database\Eloquent\Collection Get all media.
getByCollectionName ( string $collectionName ) : Illuminate\Database\Eloquent\Collection * Get all media for the given type and collection name.
getByIds ( array $ids ) : Illuminate\Database\Eloquent\Collection * Get media by ids.
getByModelType ( string $modelType ) : Illuminate\Database\Eloquent\Collection * Get all media for the given type.
getByModelTypeAndCollectionName ( string $modelType, string $collectionName ) : Illuminate\Database\Eloquent\Collection * Get all media for the given type and collection name.
getCollection ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model, string $collectionName, array | callable $filter = [] ) : Collection Get all media in the collection.

Protected Methods

Method Description
applyFilterToMediaCollection ( Collection $media, array | callable $filter ) : Collection Apply given filters on media.
getDefaultFilterFunction ( array $filters ) : Closure Convert the given array to a filter function.
loadMedia ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model, string $collectionName ) : mixed Load media by collectionName.
mediaIsPreloaded ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model ) : boolean * Determine if media is already preloaded on this model.

Method Details

__construct() public method

public __construct ( Media $model )
$model Media

all() public method

Get all media.
public all ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

applyFilterToMediaCollection() protected method

Apply given filters on media.
protected applyFilterToMediaCollection ( Collection $media, array | callable $filter ) : Collection
$media Illuminate\Support\Collection
$filter array | callable
return Illuminate\Support\Collection

getByCollectionName() public method

* Get all media for the given type and collection name.
public getByCollectionName ( string $collectionName ) : Illuminate\Database\Eloquent\Collection
$collectionName string
return Illuminate\Database\Eloquent\Collection

getByIds() public method

* Get media by ids.
public getByIds ( array $ids ) : Illuminate\Database\Eloquent\Collection
$ids array
return Illuminate\Database\Eloquent\Collection

getByModelType() public method

* Get all media for the given type.
public getByModelType ( string $modelType ) : Illuminate\Database\Eloquent\Collection
$modelType string
return Illuminate\Database\Eloquent\Collection

getByModelTypeAndCollectionName() public method

* Get all media for the given type and collection name.
public getByModelTypeAndCollectionName ( string $modelType, string $collectionName ) : Illuminate\Database\Eloquent\Collection
$modelType string
$collectionName string
return Illuminate\Database\Eloquent\Collection

getCollection() public method

Get all media in the collection.
public getCollection ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model, string $collectionName, array | callable $filter = [] ) : Collection
$model Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia
$collectionName string
$filter array | callable
return Illuminate\Support\Collection

getDefaultFilterFunction() protected method

Convert the given array to a filter function.
protected getDefaultFilterFunction ( array $filters ) : Closure
$filters array
return Closure

loadMedia() protected method

Load media by collectionName.
protected loadMedia ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model, string $collectionName ) : mixed
$model Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia
$collectionName string
return mixed

mediaIsPreloaded() protected method

* Determine if media is already preloaded on this model.
protected mediaIsPreloaded ( Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia $model ) : boolean
$model Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia
return boolean

Property Details

$model protected property

protected Media,Spatie\MediaLibrary $model
return Media