Skip to content

Laravel Nova Media Manager and Field to manage Media Polymorphic ManyToMany Relationships

License

Notifications You must be signed in to change notification settings

max26292/nova-mediable-manager

 
 

Repository files navigation

Nova Mediable Manager

This package is still in heavy development, please dont use in production

Laravel Nova Media Manager and Field to manage Polymorphic ManyToMany Relationships.

Table of Contents

Manager

Install

composer require naska-it/nova-mediable-manager
php artisan vendor:publish --provider="NaskaIt\NovaMediableManager\ToolServiceProvider"
php artisan migrate
php artisan storage:link

Configuration

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'),
        ];
    }

Flexible

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;

Credits

Where I get some code from :)

Alternatives

What I was using Before

Examples

Manager

Field

About

Laravel Nova Media Manager and Field to manage Media Polymorphic ManyToMany Relationships

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Vue 47.9%
  • PHP 40.6%
  • SCSS 8.5%
  • JavaScript 1.8%
  • Blade 1.2%