paulvl / nova-items-field
Nova field to handle array columns
1.0
2025-02-05 05:05 UTC
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