paulvl / nova-items-field
Nova field to handle array columns
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 37
Language:Vue
pkg:composer/paulvl/nova-items-field
Requires
- php: ^8.1
- ext-json: *
- laravel/nova: ^5.0
Requires (Dev)
- laravel/nova-devtool: ^1.0
README
Laravel Nova array items field with sorting, validation & many display options
Installation
composer require paulvl/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
| 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 | 
| ->indexAsList() | display items as list on index instead of total number | false | 
| ->detailsAsTotal() | display total of items on detail view instead of list | false | 
