Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ffischer's avatar

Laravel Nova Tags

Hello, I have problems with Laravel Nova to make the "tags" functional. I always get errors.

I have two entities, both in Laravel and Nova. Both work for themselves without problems. And the Laravel BelongsToMany relation is working.

Let's say I have tthese entities:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class MyCustomType extends Model
{
    protected $table = 'my_custom_type_table';

    public function entities(): BelongsToMany
    {
        return $this->belongsToMany(MyEntity::class, 'my_entity_type_table', 'type_id', 'entity_id');
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class MyEntity extends Model
{
    protected $table = 'my_entity_table';

    public function types(): BelongsToMany
    {
        return $this->belongsToMany(MyCustomType::class, 'my_entity_type_table', 'entity_id', 'type_id');
    }
}

and in Laravel Nova I have this configuration within MyEntityto add tags:

<?php

namespace App\Nova\Models;

use App\Nova\Resource;
use Laravel\Nova\Fields\Tag;

class MyEntity extends Resource
{

public function fields(NovaRequest $request)
    {
        return [
             Tag::make('MyCustomType', 'types'),
        ];
    }

this results in this error message:

Call to a member function map() on null

The Nova documentation states only "The Tag field allows you to search and attach BelongsToMany relationships using a tag selection interface.", and is silent about further configuration ... so I assumed that my config above is sufficient. But it's not.

Do you have a tip for me?

One addition/edit:

When using the BelongsToMany-Type of Nova, everything is working:

BelongsToMany::make('MyCustomType', 'types', \App\Nova\Models\MyCustomType::class),
0 likes
3 replies
ffischer's avatar

@coyote hey. I finally got it:

Tag::make('your label', 'types', MyCustomTypeAsNovaResource::class)
  1. the first argument is just the label in Nova's interface.
  2. the second is the method from my Laravel/Eloquent-model which returns a BelongsToMany-collection
  3. the third argument is the class name of the Nova-resource of the class you want to link (see an example below)
<?php

namespace App\Nova\Models;

use App\Nova\Resource;

class MyCustomTypeAsNovaResource extends Resource
{
    // [...]
    public function fields(NovaRequest $request)
    {
        return [
             Text::make('Name', 'name')->rules('required'),
        ];
    }
}
1 like
ffischer's avatar

No, unfortunately not. I now use "spatie/laravel-tags". I would like to see Nova improve the documentation about tags

1 like

Please or to participate in this conversation.