Laravel Nova Media Manager and Field to manage Polymorphic ManyToMany Relationships.
composer require naska-it/nova-mediable-manager
php artisan vendor:publish --provider="NaskaIt\NovaMediableManager\ToolServiceProvider"
php artisan migrate
php artisan storage:link
Check in config/nova-mediable-manager.php for some extra configuration Enable Manager add to app/Providers/NovaServiceProvider.php
/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [
new \NaskaIt\NovaMediableManager\NovaMediableManager
];
}
Using Field - first add HasMedia trait to your model
use NaskaIt\NovaMediableManager\HasMedia;
class Page extends Model
{
use HasMedia;
Using Field - Nova Resource
use NaskaIt\NovaMediableManager\Mediable;
class Page extends Resource
{
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
Text::make('Name'),
Trix::make('Body'),
Mediable::make('Image')
->hideFromIndex()
->isSingle(),
Mediable::make('Featured')
->isSingle(),
Mediable::make('Gallery'),
];
}
If you use Mediable field inside Flexible Layout
use NaskaIt\NovaMediableManager\Mediable;
public function fields()
{
return [
Text::make('Headline'),
Text::make('Slogan'),
Mediable::make('Block')
->isSingle()
->isFlexible(),
];
}
Add to your layout HasFlexibleMediable trait
use NaskaIt\NovaMediableManager\HasFlexibleMediable;
class BlockLayout extends Layout
{
use HasFlexibleMediable;
Where I get some code from :)
What I was using Before