Search code examples
laravellaravel-nova

Laravel nova custom fields have labels missing after upgrading


I was bugged for days with this issue so i raise this question and will also post the fix to this issue since there is no documentation for this change and not mentioned anywhere.

For anyone building custom nova components you are familiar with the element DefaultField so your .vue file has somewhere this line:

<DefaultField fieldName="MyFieldName" :fullWidthContent="false" :field="{stacked: false, visible: true}">

The problem is that in the newer laravel nova versions if you upgrade your laravel nova to 4.27.x for example the label that you have set for that field will never be displayed.

The reason for that is that in the DefaultField.vue inside your vendor file (vendor/laravel/nova/resources/js/components/DefaultField.vue)

There is a check at the start for the withLabel parameter, v-if="field.withLabel"

This causes the whole component to not include the label element and of course to look corrupted.


Solution

  • The fix for this issue is to adjust your DefaultField to include the withLabel parameter like

    <DefaultField fieldName="MyFieldName" :fullWidthContent="false" :field="{stacked: false, visible: true, withLabel: true}">
    

    I hope this answer saves time from others who will be stuck on this issue after upgrading.