Laravel Nova array items field with sorting & validation
composer require dillingham/nova-items-field
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'
];
Use Laravel's built in array validation
Items::make('Emails')->rules([
'emails.*' => 'email|min:10',
]),
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" |
Use the array to perform other actions
- make an observer
- handle the array manually
function saving($user)
{
foreach($user->emails as $email)
{
//
}
}