All Projects β†’ dcasia β†’ nova-json-wrapper

dcasia / nova-json-wrapper

Licence: MIT license
Allows you to group Nova fields and merge their output into a single JSON column

Programming Languages

PHP
23972 projects - #3 most used programming language
Vue
7211 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nova-json-wrapper

nova-url-field
A URL input and link field for Laravel Nova
Stars: ✭ 96 (+585.71%)
Mutual labels:  nova, laravel-nova-field
nova-unlayer-field
🦜 Drag’n’drop email builder for Laravel Nova that uses Adds a Laravel Nova field for Unlayer service under the hood.
Stars: ✭ 27 (+92.86%)
Mutual labels:  nova, laravel-nova-field
nova-inline-morph-to
A Laravel Nova field for displaying morphTo relationship inline.
Stars: ✭ 32 (+128.57%)
Mutual labels:  nova, laravel-nova-field
nova-hidden-field
A Laravel Nova Hidden field.
Stars: ✭ 32 (+128.57%)
Mutual labels:  nova, laravel-nova-field
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+721.43%)
Mutual labels:  nova
Nova Tags Field
A tags field to use in your Nova apps
Stars: ✭ 204 (+1357.14%)
Mutual labels:  nova
Nova Filemanager
A Filemanager tool for Laravel Nova
Stars: ✭ 189 (+1250%)
Mutual labels:  nova
Laravel Nova Nested Form
This package allows you to include your nested relationships' forms into a parent form.
Stars: ✭ 169 (+1107.14%)
Mutual labels:  nova
nova-filepond
A Nova field for uploading File, Image and Video using Filepond.
Stars: ✭ 36 (+157.14%)
Mutual labels:  laravel-nova-field
nova-select-plus
A Laravel Nova Select Field
Stars: ✭ 67 (+378.57%)
Mutual labels:  nova
nova-relationship-selector
Laravel Nova - Relationship Selector
Stars: ✭ 26 (+85.71%)
Mutual labels:  nova
Nova Colors
Single source of truth to consume Nova color values
Stars: ✭ 217 (+1450%)
Mutual labels:  nova
nova-algolia-card
A Laravel Nova card for Algolia
Stars: ✭ 22 (+57.14%)
Mutual labels:  nova
Skeleton Nova Tool
A skeleton repository for Spatie's Nova Packages
Stars: ✭ 191 (+1264.29%)
Mutual labels:  nova
nova-file-upload-field
The easiest drag-and-drop file uploading field for Laravel Nova.
Stars: ✭ 53 (+278.57%)
Mutual labels:  nova
Nova Impersonate
A Laravel Nova field allows you to authenticate as your users.
Stars: ✭ 182 (+1200%)
Mutual labels:  nova
checkout
Laravel Cart, Checkout, Orders and Coupons API with Nova Management
Stars: ✭ 36 (+157.14%)
Mutual labels:  nova
nova-chartjs
A Chart JS component for Laravel Nova
Stars: ✭ 47 (+235.71%)
Mutual labels:  nova
nova-froala-field
A Laravel Nova Froala WYSIWYG Editor Field.
Stars: ✭ 110 (+685.71%)
Mutual labels:  nova
AsyncOpenStackClient
Asyncio wrapper to OpenStack API
Stars: ✭ 17 (+21.43%)
Mutual labels:  nova

Nova Json Wrapper

Latest Version on Packagist Total Downloads License

This field allows you to group Nova fields and merge their output into a single JSON column.

Installation

You can install the package via composer:

composer require digital-creative/nova-json-wrapper

Usage

Firstly you will need to update your model to cast the value of your attribute to an array:

class User extends Model
{
    protected $casts = [
        'options' => 'array'
    ];
}

Then create a JsonWrapper field within your nova resource and use the HasJsonWrapper trait.

use DigitalCreative\JsonWrapper\JsonWrapper;
use DigitalCreative\JsonWrapper\HasJsonWrapper;

class User extends Resource
{
    use HasJsonWrapper; // Important!

    public function fields(Request $request)
    {
        //...
        JsonWrapper::make('options', [

            Text::make('First Name')->rules('required'),
            Text::make('Last Name')->rules('required'),

            JsonWrapper::make('body_mass', [

                Text::make('Weight')->rules('required'),
                Text::make('Height')->rules('required'),

            ])

        ])
    }

}

This converts to

{ "first_name": "John", "last_name": "Doe", "body_mass": { "weight": 70, "height": 180 } }

and saves to the options column on the database.

Notes

There are no visual indications that the field is wrapped within a json, this is intentional. It was designed to work in condition with Conditional Container allowing to seamlessly create complex data structure and having it all saved in a single json column into your database, here is an full example:

public function fields(Request $request)
{
    Select::make('Type')
          ->options([
              1, 2, 3, 4, 5
          ])
          ->rules('required'),

    ConditionalContainer::make([

        JsonWrapper::make('data', [

            Text::make('First Name')->rules('required'),
            Text::make('Last Name')->rules('required'),

            Select::make('Gender')
                  ->options([
                      'male' => 'Male',
                      'female' => 'Female'
                  ])
                  ->rules('required'),

            ConditionalContainer::make([ JsonWrapper::make('extra', [ ... ]) ])->if('gender === male'),
            ConditionalContainer::make([ JsonWrapper::make('extra', [ ... ]) ])->if('gender === female'),

        ])

    ])->if('type >= 2'),
}

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].