visual-ideas / moonshine-spatie-medialibrary
Spatie\MediaLibrary field for MoonShine Laravel admin panel
Installs: 5 346
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 1
Forks: 5
Open Issues: 5
Requires
- php: ^8.1
Conflicts
- moonshine/moonshine: <2.0
README
Compatibility
Installation
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:
- The spatie/laravel-medialibrary package is installed and configured
- The visual-ideas/moonshine-spatie-medialibrary package is installed
- The field passed to Spatie\MediaLibrary is added as the name of the collection via
->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(), //...