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

nzmattman's avatar

Hide relation table if empty in Nova

Is there a way to hide a HasMany relation table in nova?

I have three different HasMany relations that I only want the resource to generate the view if there are any results, otherwise I want it hidden from view.

Is that possible?

0 likes
4 replies
gty's avatar
gty
Best Answer
Level 1

You can use the function hideFromDetail and give a callback as a parameter to hide the field as you want:

HasMany::make('Posts', Post::class)
    ->hideFromDetail(fn () => $this->posts->isEmpty()),
nzmattman's avatar

@gty oh nice, i will give that a try and see if it works for this instance, thanks!

1 like

Please or to participate in this conversation.