Illizian / nova-suggest-field-container

A Laravel Nova field container allowing Text & Textarea's to contain typeahead suggestions

Home Page:https://packagist.org/packages/illizian/nova-suggest-field-container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Nova Suggest Field

Latest Version on Packagist License

Description

A container for TextArea fields that enables typeahead auto suggestions

Demo

Demo

Installation

The package can be installed through Composer.

composer require illizian/nova-suggest-field-container

Usage

Wrap your TextArea with \Illizian\NovaSuggestWrapper\NovaSuggestWrapper, like so:

/* ... */
use \Illizian\NovaSuggestWrapper\NovaSuggestWrapper;
/* ... */

class Example extends Resource
{
    /* ... */
    public function fields(Request $request)
    {
        return [
            /* ... */
            NovaSuggestWrapper::make(
                [
                    Textarea::make(__('Textarea'), 'textarea')
                ]
            )->suggestions([ "foo", "foobar" ]),
        ];
    }

You can update the trigger character with the trigger(string $char) method, for example, here we allow people to mention User's by their username using the @ character:

/* ... */
use \App\Models\User;
use \Illizian\NovaSuggestWrapper\NovaSuggestWrapper;
/* ... */

class Example extends Resource
{
    /* ... */
    public function fields(Request $request)
    {
        $users = User::all()->pluck('username')->toArray();

        return [
            /* ... */
            NovaSuggestWrapper::make(
                [
                    Textarea::make(__('Textarea'), 'textarea')
                ]
            )->trigger('@')->suggestions($users),
        ];
    }

License

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

About

A Laravel Nova field container allowing Text & Textarea's to contain typeahead suggestions

https://packagist.org/packages/illizian/nova-suggest-field-container

License:MIT License


Languages

Language:Vue 51.8%Language:PHP 42.7%Language:JavaScript 5.5%