PHP code example of moirei / media-library

1. Go to this page and download the library: Download moirei/media-library 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/ */

    

moirei / media-library example snippets


...
use MOIREI\MediaLibrary\Casts\AsMediaItem;
use MOIREI\MediaLibrary\Casts\AsMediaItems;
use MOIREI\MediaLibrary\Traits\InteractsWithMedia;

class Product extends Model
{
   use InteractsWithMedia;

   $casts = [
      'image' => AsMediaItem::class,
      'gallery' => AsMediaItems::class,
   ];
   ...
}
...

$video = File::find('video-file-id');

$product = Product::create([
   'name' => 'MOIREI MP202+',
   'image' => 'image-file-id1',
   'gallery' => ['image-file-id2', $video],
]);

php artisan vendor:publish --tag=media-library-config

php artisan vendor:publish --tag=media-library-migrations
bash
php artisan migrate