Level 1
Try this, maybe help you:
Text::make('Price', 'price', function () {
return !is_null($this->price) ? number_format($this->price, ',') : 0;
}),
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a Product model, on this model I have a custom getPriceAttribute accessor that returns Money object.
public function getPriceAttribute($price): Money
{
return new Money($price, new Currency($this->currency_code));
}
In nova I want to update the price of a product in a field.
Text::make('Price', 'price')
->displayUsing(function ($price) {
return $price->format();
})
->resolveUsing(function ($price) {
return $price->money->getAmount() / 100;
})->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$value = $request[$requestAttribute] * 100;
$model->{$attribute} = $value;
}),
When trying to update a product in Nova I get an error staying that currency code should be a string. This is because $this->currency_code is NULL in the first code snippet but I do not know why.
Just to note, the price is displayed properly on index and detail view.
Please or to participate in this conversation.