outl1ne / nova-media-hub
A Laravel Nova tool for managing media.
Fund package maintenance!
outl1ne
Installs: 32 951
Dependents: 0
Suggesters: 0
Security: 0
Stars: 46
Watchers: 4
Forks: 22
Open Issues: 15
Requires
- php: >=8.0
- laravel/nova: ^4.29.8
- outl1ne/nova-translatable: ^2.2
- outl1ne/nova-translations-loader: ^5.0
- spatie/image: ^3.0
- spatie/image-optimizer: ^1.7
- dev-main
- 2.1.0
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.8.1
- 1.8.0
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-12-09 10:46:58 UTC
README
This Laravel Nova package allows you to manage media and media fields.
Requirements
php: >=8.0
laravel/nova: ^4.0
Features
- Media Hub UI in separate view
- Media Hub field for selecting single/multiple media
- Image optimization and multiple conversions support
- File naming and path making customization
- Dark mode support
- A lot configuration options
Screenshots
Installation
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 ) ]; }
Usage
Fields
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
Casting
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');
Configure
The config file can be published using the following command:
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="config"
Custom optimizer chain
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', ])) ); }
Localization
The translation file(s) can be published by using the following command:
php artisan vendor:publish --provider="Outl1ne\NovaMediaHub\MediaHubServiceProvider" --tag="translations"
Credits
License
Nova Media Hub is open-sourced software licensed under the MIT license.