nova-kit / nova-field-mixins
Laravel Nova Field Mixins
Installs: 5 235
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ^8.0
- illuminate/support: ^8.67 || ^9.0 || ^10.0 || ^11.0
- laravel/nova: ^4.14
Requires (Dev)
- nova-kit/nova-packages-tool: ^1.3.4
- nunomaduro/larastan: ^1.0.1 || ^2.0.1
- orchestra/canvas: ^6.2 || ^7.0 || ^8.0 || ^9.0
- orchestra/testbench: ^6.38 || ^7.30 || ^8.10 || ^9.0
- phpunit/phpunit: ^9.6 || ^10.5
README
Installation
To install through composer, run the following command from the terminal:
composer require "nova-kit/nova-field-mixins"
Usages
Laravel Nova Field Mixins are useful for applying a common set of configurations to a Field without repeating it. E.g:
use Laravel\Nova\Fields\DateTime; DateTime::make('Created At')->sortable()->displayUsing(fn ($d) => $d?->diffForHumans()), DateTime::make('Updated At')->sortable()->displayUsing(fn ($d) => $d?->diffForHumans()),
By adding the following class App\Nova\Fields\Mixins\StandardDateTime
:
<?php namespace App\Nova\Fields\Mixins; use Laravel\Nova\Fields\Field; class StandardDateTime { public function __invoke(Field $field) { $field->sortable()->displayUsing(fn ($d) => $d?->diffForHumans()); } }
You can now write the above example as:
use App\Nova\Fields\Mixins\StandardDateTime; use Laravel\Nova\Fields\DateTime; DateTime::make('Created At')->apply(StandardDateTime::class), DateTime::make('Updated At')->apply(StandardDateTime::class),
Available Mixin
Handle AsArrayobject
Cast
This package provides a default implement casting for AsArrayObject
.
use Laravel\Nova\Fields\Text; use NovaKit\Fields\Mixins\AsArrayObject; Text::make('Name', 'profile.name')->apply(new AsArrayObject()),
You can also simplify this by using fromArrayObject
macro.
use Laravel\Nova\Fields\Text; Text::make('Name', 'profile.name')->fromArrayObject(),