Skip to content

Laravel Nova array items field with sorting & validation

License

Notifications You must be signed in to change notification settings

dillingham/nova-items-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nova Items Field

Latest Version on Github Total Downloads

Laravel Nova array items field with sorting & validation

laravel-nova-array-input-field

Installation

composer require dillingham/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([
    'emails.*' => 'email|min:10',
]),

Additional options

function description default
->draggable() turn on drag/drop sorting false
->fullWidth() increase the width of field area false
->listFirst() move add new to the bottom false
->placeholder($value) the new item input text "Add a new item"
->deleteButtonValue($value) value for delete button "x"
->createButtonValue($value) value for create button "Add"
->inputType(text) text, date, etc "text"

Array processing

Use the array to perform other actions

  • make an observer
  • handle the array manually
function saving($user)
{
    foreach($user->emails as $email)
    {
        //
    }
}