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

twg_'s avatar
Level 6

Nova Polymorphic Many-To-Many Issue

I evidently cannot figure out how to setup a polymorphic many-to-many relationship in Nova. I have 3 tables: items, item_category and item_categories.

Items Table

id
title
price

Item Categories Table

id
name

Item Category Table

item_id
item_category_id

Here is my Nova Files: Item

public function fields(Request $request)
{
    return [
        ID::make(),
        MorphToMany::make('Categories', itemCategories'),
    ];
}

ItemCategory

public function fields(Request $request)
{
    return [
        ID::make(),
        MorphToMany::make('Items', items'),
    ];
}

Here are my models: Item

public function categories()
{
    return $this->morphToMany(\App\Models\ItemCategory::class, 'item_category');
}

ItemCategory

public function items()
{
    return $this->morphToMany(\App\Models\Item::class, 'item');
}
0 likes
0 replies

Please or to participate in this conversation.