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

packy's avatar
Level 7

Field value based on relationship

I am trying to make some readonly fields that their values are populated by a relationship value the admin selects. So in short, when they create a new order the "email" field for the order is readonly and will fill out on based upon the "retailer" they select to save time.

I tried this but its not working

BelongsTo::make('Retailer', 'retailer', Retailer::class)
                ->sortable(),

            Text::make('Name')
                ->dependsOn(
                    ['retailer'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        $retailer = $formData->resource(Retailer::uriKey());
                        $field->value = $retailer->name;
                    }
                )
                ->readonly(),
0 likes
0 replies

Please or to participate in this conversation.