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

nishant4317's avatar

BelongsTo Through Relation[NOVA]

If I have three resources:

Post

id, name

Comment

id, comment, post_id

Rating

id, rating, comment_id

Code In Rating resources' field:

BelongsTo::make('Post', 'comment', Post::class)->withMeta([ 'belongsToId' => isset($this->comment['post']['id']) ? $this->comment['post']['id'] : null, ])->displayUsing(function ($comment) { return $comment->post->name; }),

I can easily write a BelongsTo field for getting the comment for a Rating and perform CRUD operations. But now I want to update my Post details too from the Rating Resource. How can I achieve this?. I'm able to display the Post name on my Rating resources' index and detail page. But it fails when I try to update/insert to Rating resource. Because it tries to insert/update the data into Rating resource and not into the comment resource.

I will be glad if someone could provide me a workaround for this problem. Thank you.

0 likes
1 reply
bobbybouwmann's avatar

Nova isn't really build to work this way. Instead, you need to go to the post edit page and edit the details in there.

The current workaround you have works, but is not ideal in most cases. It seems that you're trying to work around the philosophy of Nova to keep things simpel.

Please or to participate in this conversation.