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

speedball's avatar

BelongsToMany with pivot and relation

I have a belongsTo relation which displays contacts via a pivot table. I have defined the model relations with ->using() and that works. The pivot table has extra fields which I can also display in Nova by using

->fields(function () { return [
    Text::make('invite_id')
]});

which also works fine. My problem is now that the pivot table has a HasMany relation which I would like to show on the details page but the relation never shows.

->fields(function ($) {
    return [
       HasMany::make('UserMessages'),
       Text::make('invite_id')
]})

Do relations work inside the fields() method of a belongsTo relation?

In Tinker I can query the data like this:

Card->contacts->first->pivot->messages

Thanks ...

0 likes
0 replies

Please or to participate in this conversation.