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

Synchro's avatar

Dynamic fields don't appear on edit & create layouts

I have a Point field (with a matching cast) in a Location class. The field has latitude and longitude properties that need to be separate Number edit fields in Nova, so I need to split them out for edit, and then recombine them on save. A naïve approach for one of the properties is:

 Number::make('Latitude', function () {
    return $this->location->latitude;
})

This makes it appear on the index and display pages correctly, but it's just not there on the edit or create pages. From the docs and this article I gather I need to provide fillUsing to map the input value back into the internal property when saving:

->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
    $this->location->latitude = $request->input($requestAttribute);
})

but that seems to do nothing, so I added a resolveUsing call to try to close the gap – though I don't get what this might be doing that's different from the original field definition:

->resolveUsing(function ($value, Location $model) {
    return $model->latitude;
})

but it still doesn't appear on the edit or create pages. I assume I'm doing something wrong, or I've missed something, but I don't know what, though this all looks overcomplicated. Any ideas?

0 likes
1 reply
Synchro's avatar

After sleeping on this, I thought that I don't need to compute the value in the field definition, but do need to remap it in and out of the model, and this indeed allows the field to at last appear on the edit page, with the correct value:

                Number::make('Latitude')
                    ->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
                        $model->location->latitude = (float)$request->input($requestAttribute);
                    })
                    ->resolveUsing(function ($value, \App\Models\Location $model) {
                        return $model->location->latitude;
                    })

This tells me that resolveUsing is doing its job. However, on trying to save, it fails with a JsonEncodingException:

Unable to encode attribute [original] for model [Laravel\Nova\Actions\ActionEvent] to JSON: Malformed UTF-8 characters, possibly incorrectly encoded.

So fillUsing is not working here, and I don't know why a simple float value would cause a JSON encoding issue.

Please or to participate in this conversation.