PHP code example of juniorfontenele / spatie-nova-tags-field

1. Go to this page and download the library: Download juniorfontenele/spatie-nova-tags-field library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juniorfontenele / spatie-nova-tags-field example snippets


class BlogPost extends \Illuminate\Database\Eloquent\Model
{
    use \Spatie\Tags\HasTags;
    
    ...
}

namespace App\Nova;

use Spatie\TagsField\Tags;

class BlogPost extends Resource
{
    // ...
    
    public function fields(Request $request)
    {
        return [
            // ...
            
            Tags::make('Tags'),

            // ...
        ];
    }
}

Tags::make('Tags')->withoutSuggestions(),

Tags::make('Tags')->limitSuggestions($maxNumberOfSuggestions),

Tags::make('Tags')->limit($maxNumberOfTags),

// in your Nova resource

public function fields(Request $request)
{
    return [
        // ...
        
        Tags::make('Tags')->type('my-special-type'),

        // ...
    ];
}

// in your Nova resource

public function fields(Request $request)
{
    return [
        // ...
        
        Tags::make('Tags')->single(),

        // ...
    ];
}

// in your Nova resource

public function fields(Request $request)
{
    return [
        // ...
        
        Tags::make('Tags')->single()->canBeDeselected(),

        // ...
    ];
}

// in your Nova resource

public function fields(Request $request)
{
    return [
        // ...
        
        Tags::make('Categories', 'tags')->withMeta(['placeholder' => 'Add categories...']),

        // ...
    ];
}

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Spatie\Tags\Tag as TagModel;

class Tag extends Resource
{
    public static $model = TagModel::class;

    public static $title = 'name';

    public static $search = [
        'name',
    ];

    public function fields(Request $request)
    {
        return [
            Text::make('Name')->sortable(),
        ];
    }
}

Tags::make('Tags')->withLinkToTagResource() // The resource App\Nova\Tag will be used
Tags::make('Tags')->withLinkToTagResource(\Custom\CustomTag::class) // The resource \Custom\CustomTag will be used