https://github.com/dillingham/nova-items-field
Laravel Nova array items field with sorting & validation
https://github.com/dillingham/nova-items-field
laravel laravel-nova laravel-nova-field
Last synced: 2 months ago
JSON representation
Laravel Nova array items field with sorting & validation
- Host: GitHub
- URL: https://github.com/dillingham/nova-items-field
- Owner: dillingham
- License: mit
- Created: 2019-01-10T18:19:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-04T08:58:57.000Z (about 3 years ago)
- Last Synced: 2025-03-29T05:11:14.482Z (2 months ago)
- Topics: laravel, laravel-nova, laravel-nova-field
- Language: Vue
- Homepage:
- Size: 272 KB
- Stars: 114
- Watchers: 1
- Forks: 34
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
## Nova Items Field
[](https://packagist.org/packages/dillingham/nova-items-field)
[](https://packagist.org/packages/dillingham/nova-items-field) [](https://twitter.com/im_brian_d)Laravel Nova array items field with sorting, validation & many [display options](https://github.com/dillingham/nova-items-field#additional-options)

### Installation
```
composer require dillingham/nova-items-field
```### Usage
```php
use NovaItemsField\Items;
```
```php
function fields() {
return [
Items::make('Emails'),
]
}
```
and be sure to [cast](https://laravel.com/docs/5.7/eloquent-mutators#array-and-json-casting) the property as an array on your eloquent model
```php
public $casts = [
'emails' => 'array'
];
```
### Validation
Use Laravel's built in [array validation](https://laravel.com/docs/5.7/validation#validating-arrays)
```php
Items::make('Emails')->rules([
'emails.*' => 'email|min:10',
]),
```
Manually setting the attribute may be needed in some cases.
```php
Items::make('Long Text', 'attribute')->rules([
'attribute.*' => 'email|min:10',
]),
```
### Array processingUse the array to perform other actions by making an [observer](https://nova.laravel.com/docs/1.0/resources/#resource-events)
```php
function saving($user)
{
foreach($user->emails as $email)
{
//
}
}
```### Replace item vue component
Here's a brief walkthrough to customize the vue item - [view](https://github.com/dillingham/nova-items-field/issues/10#issuecomment-527315057)
### Additional options
| function | description | default |
| - | - | - |
| `->max(number)` | limit number of items allowed | false |
| `->draggable()` | turn on drag/drop sorting | false |
| `->fullWidth()` | increase the width of field area | false |
| `->maxHeight(pixel)` | limit the height of the list | false |
| `->listFirst()`| move add new to the bottom | false |
| `->inputType(text)` | text, date, etc | "text" |
| `->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" |
| `->hideCreateButton()` | hide the "add" button | false |---
# Author
Hi 👋, Im Brian Dillingham, creator of this Nova package [and others](https://novapackages.com/collaborators/dillingham)
Hope you find it useful. Feel free to reach out with feedback.
Follow me on twitter: [@im_brian_d](https://twitter.com/im_brian_d)