Laravel Nova Media Library

Tool and Field for Laravel Nova that will let you managing images and add them to the posts as single image or gallery

Table of Contents

Install

composer require classic-o/nova-media-library
php artisan vendor:publish --provider="ClassicO\NovaMediaLibrary\ToolServiceProvider"
php artisan migrate
php artisan storage:link

Usage

Add the below to the tools function in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        new \ClassicO\NovaMediaLibrary\NovaMediaLibrary(),
    ];
}

Add Field to the resource

use ClassicO\NovaMediaLibrary\MediaField;

class Post extends Resource
{
    ...
     public function fields(Request $request)
        {
            return [
                ...
                MediaField::make('Image', 'image'),
                ...
            ];
        }
    ...
}

Configuration

# config/media-library.php
return [

	# Will use to return base url of app.
	'url'       => env('APP_URL', '') . '/storage',

	# Will use to put file uploads in `/storage/app/public`
	'folder'    => '/media/',

	# Organize my uploads into year-month based folders.
	# `/storage/app/public/{folder}/YYYY-MM/`
	'split'     => true,

	# This option let you to filter your image by extensions.
	'type'      => ['jpg', 'jpeg', 'png', 'gif', 'svg'],

	# The number of files that will be returned with each step.
	# (The tool loads images from a folder not all at once).
	'step'      => 40,

];

Customization

By default, this field is used as single image. If you need set field as gallery, add method:

MediaField::make('Image', 'image')
          ->isGallery()

If you want to hide the gallery under the accordion, add the following method

MediaField::make('Image', 'image')
          ->isGallery()
          ->isHidden()

Screenshots

Media Library

Details

Multiple select

Single image

Gallery