blendbyte/nova-items-field

Nova field to handle array columns

Installs: 210 196

Dependents: 0

Suggesters: 0

Security: 0

Stars: 12

Watchers: 1

Forks: 32

Open Issues: 1

Language:Vue

1.3.4 2024-03-11 03:38 UTC

This package is auto-updated.

Last update: 2024-09-11 04:49:57 UTC


README

Laravel Nova array items field with sorting, validation & many display options

nova-array-input-field

Installation

composer require blendbyte/nova-items-field

Usage

use NovaItemsField\Items;
function fields() {
    return [
        Items::make('Emails')
    ]
}

and be sure to cast the property as an array on your eloquent model

public $casts = [
    'emails' => 'array'
];

Validation

Use Laravel's built in array validation

Items::make('Emails')->rules([
     null => 'required|min:2'
     '*' => 'email|min:10',
]),

In this case, an error is produced if there aren't at least 2 items in the array and if each item is not a valid email or is shorter than 10 characters.

You might prefer to use explicit attribute names, the behaviour is exactly the same as before

Items::make('Emails', 'user_email')->rules([
    'user_email' => 'required|min:2',
    'user_email.*' => 'email|min:10',
]),

Array processing

Use the array to perform other actions by making an observer

function saving($user)
{
    foreach($user->emails as $email)
    {
        //
    }
}

Replace item vue component

Here's a brief walkthrough to customize the vue item - view

Additional options