A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
Switch branches/tags
Clone or download
Latest commit c15bbef Oct 19, 2018
Permalink
Failed to load latest commit information.
dist fixed preview bug Oct 1, 2018
docs - added docs Oct 1, 2018
resources fixed preview bug Oct 1, 2018
src Update Images.php Oct 19, 2018
.gitignore init Oct 1, 2018
composer.json init Oct 1, 2018
docker-compose.yml init Oct 1, 2018
package.json init Oct 1, 2018
readme.md Update readme.md Oct 19, 2018
webpack.mix.js init Oct 1, 2018
yarn.lock init Oct 1, 2018

readme.md

Laravel Advanced Nova Media Library

Manage images of spatie's media library package. Upload multiple images and order them by drag and drop.

This package is inspired by the basic nova media library which lacks the upload of multiple images and ordering. This package is one of the dependencies, so you can use it beside this package.

Install

composer require ebess/advanced-nova-media-library

Model media configuration

Let's assume you configured your model to use the media library like following:

use Spatie\MediaLibrary\Models\Media;

public function registerMediaConversions(Media $media = null)
{
    $this->addMediaConversion('thumb')
        ->width(130)
        ->height(130);
}

public function registerMediaCollections()
{
    $this->addMediaCollection('main')->singleFile();
    $this->addMediaCollection('my_multi_collection');
}

Single image upload

Single image upload

use Ebess\AdvancedNovaMediaLibrary\Fields\Images;

public function fields(Request $request)
{
    return [
        Images::make('Main image', 'main') // second parameter is the media collection name 
            ->thumbnail('thumb') // conversion used to display the image
            ->rules('required'), // validation rules
    ];
}

Multiple image upload

If you enable the multiple upload ability, you can order the images via drag & drop.

Multiple image upload

use Ebess\AdvancedNovaMediaLibrary\Fields\Images;

    public function fields(Request $request)
    {
        return [
            Images::make('Images', 'my_multi_collection'), // second parameter is the media collection name
                ->conversion('medium-size') // conversion used to display the "original" image
                ->thumbnail('thumb') // conversion used to display the image
                ->multiple() // enable upload of multiple images - also ordering
                ->fullSize() // full size column
                ->rules('required|size:3'), // validation rules for the collection of images
                // validation rules for the collection of images
                ->singleImageRules('dimension:min_width=100'),
        ];
    }

File media management

To manage files just use the nova media library fields which are already required in this package.