outl1ne/nova-media-hub is a Laravel package for a laravel nova tool for managing media..
It currently has 46 GitHub stars and 57.501 downloads on Packagist (latest version 3.0.4).
Install it with composer require outl1ne/nova-media-hub.
Discover more Laravel packages by outl1ne
or browse all Laravel packages to compare alternatives.
Last updated
This Laravel Nova package allows you to manage media and media fields.
php: >=8.2laravel/nova: ^5.0

Install the package in a Laravel Nova project via Composer and run migrations:
# Install nova-media-hub
composer require outl1ne/nova-media-hub
# Run migrations
php artisan migrate
Register the tool with Nova in the tools() method of the NovaServiceProvider:
// 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
)
];
}
This package provides a field MediaHubField which allows you to select media. This saves the media as a JSON array into the database.
Example usage:
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
The media column of models can be automatically cast as a Collection of Media models:
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');
The config file can be published using the following command:
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="config"
Each collection in the Media Hub sidebar has an edit button that renames the collection and moves all of its media items along with it. Files on disk are stored under a path derived from the media ID, so nothing is moved on the disk and existing media URLs keep working.
Renaming is only available when user_can_create_collections is enabled in the config, since a rename
introduces a new collection name. Collections listed under the collections config key always exist and
can't be renamed, so they have no edit button.
You can define a custom optimizer chain or add items to it like so:
// 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',
]))
);
}
The translation file(s) can be published by using the following command:
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="translations"
Nova Media Hub is open-sourced software licensed under the MIT license.