nova-kit/nova-field-mixins

Laravel Nova Field Mixins

v1.0.0 2021-12-21 23:44 UTC

This package is auto-updated.

Last update: 2022-01-22 00:03:03 UTC


README

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Installation

To install through composer, run the following command from terminal:

composer require "nova-kit/nova-field-mixins"

Usages

Laravel Nova Field Mixins is useful to apply set common set of configuration to Field without repeating it. E.g:

use Laravel\Nova\Fields\DateTime;

DateTime::make('Created At')->sortable()->firstDayOfWeek(1),
DateTime::make('Updated At')->sortable()->firstDayOfWeek(1),

By adding 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()->firstDayOfWeek(1);
    }
}

You can now write 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 provide a default implement casting for AsArrayObject.

use Laravel\Nova\Fields\Text;
use NovaKit\Fields\Mixins\AsArrayObject;

Text::make('Name', 'profile.name')->apply(new AsArrayObject()),