New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

reedware/nova-field-manager

Creates a field facade for referencing fields.
6,700
Install
composer require reedware/nova-field-manager
Latest Version:v1.0.2
PHP:>=7.1.0
Laravel:5 – 8
License:MIT
Last Updated:Jun 13, 2021
Links: GitHub  ·  Packagist
Maintainer: tylernathanreed

Nova Field Manager

This package provides the convenience of not having to include the class path of each individual field in your resource class declaration. A new Field facade will be created, where you can defer all field creation through.

Latest Stable Version Total Downloads License

Installation

Require this package with composer.

composer require reedware/nova-field-manager

Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the service provider or facade. However, should you still need to reference them, here are their class paths:

\Reedware\NovaFieldManager\NovaFieldManagerServiceProvider::class // Service Provider
\Reedware\NovaFieldManager\Facade::class // Facade

Usage

You can now add fields to your resources in Nova by using the Field facade, rather than having to include each individual field in your resource class definition.

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        Field::id()->sortable(),

        Field::text('Name', 'display_name')
            ->sortable()
            ->rules('required', 'max:100'),

        Field::textarea('Description')
            ->rules('max:255'),

        Field::hasMany('Tasks', 'tasks', Task::class),

        Field::number('Tasks', function() {
            return $this->tasks_count;
        })

    ];
}

Custom Fields

All of the fields are configured in the nova-fields configuration file. First, you will need to create your own copy, by either running the php artisan vendor:publish command, or by copying the configuration file directory from this repository (found in ~/config/nova-fields.php).

You can easily add your own (or override the default fields) by manipulating this configuration file. The config key (id, text, hasMany, etc) is the method that you can call from the Field facade. The config value is the class path to the field, where a call to Field::<key>(...) defers to <value>::make(...).

The default fields provided by Nova will automatically be added, even if they are not present in your configuration file. However, if you have overridden one of the default fields (by specifying the same key name), your field will override the default Nova field.

<?php

return [
  
  /**
   * Custom Fields
   */
   'custom' => \NovaComponents\CustomField\Field::class

];
/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        Field::custom(...)
    ];
}

Related Packages

epartment/nova-dependency-container

A Laravel Nova field container allowing to depend on other fields values

4,693,752 378
eminiarts/nova-tabs

Laravel Nova - Tabs.

4,610,439 464
ebess/advanced-nova-media-library

Laravel Nova tools for managing the Spatie media library.

3,857,876 616
spatie/nova-tags-field

A tags field for Nova apps

2,337,323 301
kabbouchi/nova-impersonate

A Laravel Nova field allows you to authenticate as your users.

2,268,645 234

Version History

Version Released PHP Laravel License
v1.0.2 >=7.1.0 >=5.6 MIT
v1.0.1 >=7.1.0 >=5.6 MIT
v1.0.0 >=7.1.0 >=5.6 MIT