Skip to content

Commit

Permalink
Merge pull request #7 from DissNik/patch-2
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
alexvenga authored Dec 23, 2023
2 parents 71bacc9 + fa983b4 commit 1f0cef6
Showing 1 changed file with 88 additions and 3 deletions.
91 changes: 88 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,92 @@
# Spatie\MediaLibrary field for [MoonShine Laravel admin panel](https://moonshine.cutcode.dev)
# 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)

## Documentation
[Read Spatie\MediaLibrary field in Official MoonShine Documentation](https://moonshine.cutcode.dev/section/fields-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(),

//...
```

0 comments on commit 1f0cef6

Please sign in to comment.