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

garrettmassey's avatar

Nova BelongsToMany - Hide fields from relationship's index, but not resource index

Say I have two models / resources: Business and Environment. A business belongs to many environments, an environment can belong to many businesses.

On Nova, I have each individual resource set up, and one of the fields I have on the environment resource index is the number of businesses linked to that environment, as a "quick glance" to sort by most used environment features, things like that.

Now, when I click on a specific Business, I can see the environments for that business, but I can also see all of the fields I have defined for the environments index. I only really want and need to see the name and the pivot column "notes" for the environment that is attached to a business.

Is there a way to specify that a field should only show up on a resource's index, not on the relationship details?

Business fields:

    return [
        ID::make()->sortable(),
        Text::make('Business Name')->sortable(),
        BelongsToMany::make('Environment Details', 'environments', Environment::class)
            ->fields(function () {
                return [
                    Text::make('Notes')->nullable(),
                ];
            }),
    ];

Environment Fields:

    return [
        Stack::make('Name & Description', 'name', [
            Line::make('Name')
                ->asHeading(),
            Line::make('Description')
                ->asSmall(),
        ])->sortable()
            ->onlyOnIndex(),

        Text::make('Name')
            ->sortable()
            ->rules('required', 'max:255')
            ->creationRules('unique:accommodations,name')
            ->updateRules('unique:accommodations,name,{{resourceId}}')
            ->showOnIndex(false),
        
        BelongsToMany::make('Providers With This Environment', 'providers', Provider::class),
        
        Number::make('# Providers', 'providers_count')
            ->sortable()
            ->onlyOnIndex(),

        ...AttributeStatusBadge::make($this->resource),

        ...Metadata::make($this->resource),
    ];
0 likes
2 replies
garrettmassey's avatar

@jdc1898 Sorry for the long pause before the reply, I just checked out that issue and the solutions proposed worked!

For reference for anyone else looking for this:

->hideFromIndex(function (ResourceIndexRequest $request) {
    return $request->viaRelationship();
}),

chaining the above on the fields I wanted hidden from relationship pages worked like a charm! Thank you!

Please or to participate in this conversation.