Code Monkey home page Code Monkey logo

moonshine-spatie-medialibrary's Introduction

Spatie\MediaLibrary field for MoonShine Laravel admin panel

Latest Version on Packagist Total Downloads

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 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(),

//...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.