PHP code example of outl1ne / nova-media-hub

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

    

outl1ne / nova-media-hub example snippets


// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        \Outl1ne\NovaMediaHub\MediaHub::make()
        // You can choose to hide the Tool from the sidebar
          ->hideFromMenu()

          // Optionally add additional fields to Media items
          ->withCustomFields(
            ['copyright' => __('Copyright')],
            overwrite: false
          )
    ];
}

use Outl1ne\NovaMediaHub\Nova\Fields\MediaHubField;

// ...

MediaHubField::make('Media', 'media')
  ->defaultCollection('products') // Define the default collection the "Choose media" modal shows
  ->multiple(), // Define whether multiple media can be selected

class Product extends Model
{
    protected $casts = [
        'media' => \Outl1ne\NovaMediaHub\Casts\MediaCast::class,
    ];
}

    $cover = Product::first()->media->first();

    // ...

    $urls = Product::first()->media->pluck('url');

    // ...

    $collection = Product::first()->media->where('collection_name', 'Details');

// in app/Providers/AppServiceProvided.php

public function register() {
  // ...

  // https://github.com/spatie/image-optimizer#creating-your-own-optimization-chains
  \Outl1ne\NovaMediaHub\MediaHub::withOptimizerChain(
    (new OptimizerChain)
      ->addOptimizer(new Jpegoptim([
        '--strip-all',
        '--all-progressive',
      ]))
      ->addOptimizer(new Pngquant([
        '--force',
      ]))
  );
}

bash
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="translations"