PHP code example of visual-ideas / moonshine-spatie-medialibrary

1. Go to this page and download the library: Download visual-ideas/moonshine-spatie-medialibrary library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

visual-ideas / moonshine-spatie-medialibrary example snippets


composer 

use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
 
class ModelClass extends Model implements HasMedia
{
    use InteractsWithMedia;
 
    //...
    
    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('cover');
    }
    
    //...
}

use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;

//...

MediaLibrary::make('Cover', 'cover'),

//...

use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
 
class ModelClass extends Model implements HasMedia
{
    use InteractsWithMedia;
    
    //...
    
    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('cover')->singleFile();
    }
    
    //...
}

use VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary;

//...

MediaLibrary::make('Gallery', 'gallery')->multiple(),

//...