LaravelPackages.net
Acme Inc.
Toggle sidebar
gwd/laravel-nova-flexible-content

A Laravel Nova field.

2.268
1
0.0.1
About gwd/laravel-nova-flexible-content

gwd/laravel-nova-flexible-content is a Laravel package for a laravel nova field.. It currently has 1 GitHub stars and 2.268 downloads on Packagist (latest version 0.0.1). Install it with composer require gwd/laravel-nova-flexible-content. Discover more Laravel packages by gwd or browse all Laravel packages to compare alternatives.

Last updated

Laravel nova field: Flexible content

This is a Laravel Nova field which makes it possible to do a flexible setup field, which can be controlled within 1 json column in a model.

You can install the field by running the following command:

composer require gwd/laravel-nova-flexible-content

Then open the nova resource which should use have the Flexible content field.

Screenshot of Laravel Nova Flexible Field

What is required in the Resource?

Its very important that the resource have a column which of type json and the field is casts to array:

class ... extends Migration
{
   public function up()
   {
      Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->json('flexible')->nullable(); // This field

            $table->timestamps();
        });
   }
}

And then in the Model:

class Post extends Model
{
    protected $casts = [
        'flexible' => 'array'
    ];
}

Then you can use the Flexible content field, by doing the following setup:

use Gwd\FlexibleContent\FlexibleContent;

class Post extends Resource
{
   ...
   public function fields(Request $request)
   {
       return [
            FlexibleContent::make('Flexible')
                ->addLayout(
                [
                    'label' => 'Full screen image',
                    'name' => 'full_image',
                    'fields' => [
                        [
                            'type' => 'text',
                            'name' => 'title',
                            'placeholder' => 'Enter a title here',
                            'required' => true
                        ],
                        [
                            'type' => 'image',
                            'name' => 'image',
                            'label' => 'Image',
                            'multiple' => false,
                            'required' => true
                        ]
                    ]
             ])
       ];
   }
}

In the above example you get the following output in the flexible column:

[
  {
    "data": {
      "title": "This is a title",
      "image": "IMAGE-PATH-HERE",
    },
    "type": "full_image"
  }
]

Star History Chart