phplaravellaravel-nova

Laravel Nova: How to deny to change field value on update?


How to deny to change field value on update in Laravel Nova?

This field should be editable on creating.

I tried to save previous values with observers but something tells me that this is not an optimal way to do it. May be there is another way to do it?


Solution

  • You can mark a field as readonly based on a condition:

    Boolean::make('Example', 'example')
     ->readonly(fn (NovaRequest $request) => $request->isUpdateOrUpdateAttachedRequest())
    

    Source: https://nova.laravel.com/docs/resources/fields.html#readonly-fields