Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/visual-ideas/moonshine-spatie-medialibrary
Spatie\MediaLibrary field for MoonShine Laravel admin panel
https://github.com/visual-ideas/moonshine-spatie-medialibrary
eloquent gallery images laravel media moonshine php spatie spatie-laravel-medialibrary spatie-media-library upload vi visualideas
Last synced: 3 months ago
JSON representation
Spatie\MediaLibrary field for MoonShine Laravel admin panel
- Host: GitHub
- URL: https://github.com/visual-ideas/moonshine-spatie-medialibrary
- Owner: visual-ideas
- License: mit
- Created: 2023-04-08T09:36:34.000Z (almost 2 years ago)
- Default Branch: 2.x
- Last Pushed: 2024-06-02T21:39:39.000Z (8 months ago)
- Last Synced: 2024-11-07T07:18:04.362Z (3 months ago)
- Topics: eloquent, gallery, images, laravel, media, moonshine, php, spatie, spatie-laravel-medialibrary, spatie-media-library, upload, vi, visualideas
- Language: PHP
- Homepage: https://moonshine.cutcode.dev/section/fields-spatie-medialibrary
- Size: 28.3 KB
- Stars: 16
- Watchers: 1
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spatie\MediaLibrary field for [MoonShine](https://moonshine-laravel.com) Laravel admin panel
[![Latest Version on Packagist](https://img.shields.io/packagist/v/visual-ideas/moonshine-spatie-medialibrary.svg?style=flat-square)](https://packagist.org/packages/visual-ideas/laravel-site-settings)
[![Total Downloads](https://img.shields.io/packagist/dt/visual-ideas/moonshine-spatie-medialibrary.svg?style=flat-square)](https://packagist.org/packages/visual-ideas/moonshine-spatie-medialibrary)## Compatibility
| MoonShine | Moonshine Spatie Medialibrary | Currently supported |
|:---------------------:|:-----------------------------:|:-------------------:|
| \>= v1.52 and < v2.0 | <= v1.2.0 | no |
| >= v2.0 | >= v2.0.1 | yes |## Installation
The field is purposed for work with the [Laravel-MediaLibrary](https://github.com/spatie/laravel-medialibrary)
package made by [Spatie](https://github.com/spatie/laravel-medialibrary) and extends default field
[Image](https://moonshine-laravel.com/docs/section/fields-image)```php
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:
```php
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:```php
use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;//...
MediaLibrary::make('Cover', 'cover'),
//...
```By default, the field works in a single image mode
```php
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
```php
use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;//...
MediaLibrary::make('Gallery', 'gallery')->multiple(),
//...
```