outhebox/nova-hidden-field

A Laravel Nova Hidden field.

v1.0.3 2020-05-20 14:43 UTC

This package is auto-updated.

Last update: 2020-10-24 01:51:42 UTC


README

GitHub license GitHub issues Total Downloads

Description

This field give the ability to add a hidden fields to your resources.

Requrements

  • Laravel 5.7+ with Nova.

Installation

This package can be installed through Composer.

composer require outhebox/nova-hidden-field

Example Usage

Add the field to your resource in the fields method:

use Outhebox\NovaHiddenField\HiddenField;

HiddenField::make('User', 'user_id')
    ->current_user_id(),

Also you can override the default value:

use Outhebox\NovaHiddenField\HiddenField;

HiddenField::make('User', 'column_name')
    ->defaultValue($this->get_client_id()),

/**
 * Function will return your value
 * the returned value should be string
 * 
 * @return string
 */
public function get_client_id()
{
    $client = Client::find(1)->first();
    return $client->id;
}

Another option you may like if you want to use the relationship fields:

use Laravel\Nova\Fields\BelongsTo;
use Outhebox\NovaHiddenField\HiddenField;

HiddenField::make('User', 'user_id')
    ->hideFromIndex(),
    ->hideFromDetail(),
    ->current_user_id()

BelongsTo::make('User')
    ->hideWhenCreating(),
    ->hideWhenUpdating(),

License

The MIT License (MIT). Please see License File for more information.

Donate

If you like this package, you can show your appreciation 💜 by donating any amount via Patreon to support ongoing development.