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

iamDiscovery's avatar

Values shown on BelongsTo drop down in Nova

Hi all, I'm struggling a bit with a drop down I'm trying to use in Nova. As is, I have a products table and a sizes table and I'm using

BelongsTo::make('Size', 'size', 'App\Nova\Sizes')->hideFromIndex()

to get the fields from the sizes table to assign to new fields created in products. In the sizes table, I have two columns "Amount" and "Measurement", however, when using the drop down when creating a new product it only displays the amount. This is an issue as it means they'll show as "100.00" instead of "100.00 ml" for example. I've had a look at both computed fields and accessors, but didn't entirely understand either and I'm still unsure how to access values in the sizes table to concatenate both the amount and measure columns together to display in the drop down in a products creation.

Any help at all is appreciated.

0 likes
1 reply
iamDiscovery's avatar
iamDiscovery
OP
Best Answer
Level 4

For anyone else looking to do something similar, I managed to find a solution. I'm now doing it by using the following:

BelongsTo::make('Weight', 'weight', 'App\Nova\Weights')
->display(function($weightSelection){
return $weightSelection->amount.' '.$weightSelection->measurement;
})->hideFromIndex(),

Found this solution here: https://stackoverflow.com/a/55047107/16748707

Please or to participate in this conversation.