Simple Nova field for flat array inputs
composer require dillingham/nova-items-field
use NovaItemsField\Items;
Items::make('Emails')->values($this->emails),
function | description | required | default |
---|---|---|---|
values(array) | add a model's array | Yes | -- |
inputType(text) | text, date, etc | No | "text" |
fullWidth(boolean) | increase size of field | No | false |
placeholder(text) | the new item input text | No | "Add a new item" |
listFirst() | move form after the list | No | false |
deleteButtonValue(html) | value for delete button | No | "x" |
createButtonValue(html) | value for create button | No | "Add" |
Items::make('Emails')->values($this->emails)->rules([
'emails.*' => 'email|min:10',
]),
Be sure to cast emails
to an array in your eloquent model.
public $casts = [
'emails' => 'array'
];
Don't want to store the array?
Use the array as a temporary variable
- make an observer
- handle the array manually.
- unset the array to avoid sql error
function saving($user)
{
foreach($user->emails as $email)
{
//
}
unset($user->emails);
}
- Laravel array validation
- Sortable / draggable items