Spatie\MediaLibrary field for MoonShine Laravel admin panel
visual-ideas/moonshine-spatie-medialibrary is a Laravel package for spatie\medialibrary field for moonshine laravel admin panel.
It currently has 20 GitHub stars and 18.787 downloads on Packagist (latest version 4.1.0).
Install it with composer require visual-ideas/moonshine-spatie-medialibrary.
Discover more Laravel packages by visual-ideas
or browse all Laravel packages to compare alternatives.
Last updated
| MoonShine | Moonshine Spatie Medialibrary | Currently supported | |:--------------------:|:-----------------------------:|:-------------------:| | >= v1.52 and < v2.0 | <= v1.2.0 | no | | >= v2.0 | >= v2.0.1 | yes | | >= v3.0 | >= v3.0.0 | yes | | >= v4.0 | >= v4.0.0 | yes |
The field is purposed for work with the Laravel-MediaLibrary package made by Spatie and extends default field Image
composer require visual-ideas/moonshine-spatie-medialibrary
Before using the Spatie\MediaLibrary field, make sure that:
->addMediaCollection('Field')In the model:
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class ModelClass extends Model implements HasMedia
{
use InteractsWithMedia;
//...
public function registerMediaCollections(): void
{
$this->addMediaCollection('cover');
}
//...
}
In the MoonShine:
use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;
//...
MediaLibrary::make('Cover', 'cover'),
//...
By default, the field works in a single image mode
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class ModelClass extends Model implements HasMedia
{
use InteractsWithMedia;
//...
public function registerMediaCollections(): void
{
$this->addMediaCollection('cover')->singleFile();
}
//...
}
If you want to use a field to load multiple images, add the ->multiple() method when declaring the field
use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;
//...
MediaLibrary::make('Gallery', 'gallery')->multiple(),
//...