F
Filament2y ago
WrkL

How to properly access relation data in ViewField

Hi, i am using a standalone form builder, i have below ViewField
ViewField::make('bin.bin_description')
->label('Bin')
->view('filament.forms.fields.span'),
ViewField::make('bin.bin_description')
->label('Bin')
->view('filament.forms.fields.span'),
and this is the component :
<x-dynamic-component
:component="$getFieldWrapperView()"
:id="$getId()"
:label="$getLabel()"
:label-sr-only="$isLabelHidden()"
:helper-text="$getHelperText()"
:hint="$getHint()"
:hint-action="$getHintAction()"
:hint-color="$getHintColor()"
:hint-icon="$getHintIcon()"
:required="$isRequired()"
:state-path="$getStatePath()"
>
<div x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }">
<span x-text="state ? state : 'abc'"></span>
</div>
</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:id="$getId()"
:label="$getLabel()"
:label-sr-only="$isLabelHidden()"
:helper-text="$getHelperText()"
:hint="$getHint()"
:hint-action="$getHintAction()"
:hint-color="$getHintColor()"
:hint-icon="$getHintIcon()"
:required="$isRequired()"
:state-path="$getStatePath()"
>
<div x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }">
<span x-text="state ? state : 'abc'"></span>
</div>
</x-dynamic-component>
it work if there is relation data for bin but it will throw below error in console if no relation data
4 Replies
Dan Harrin
Dan Harrin2y ago
dot syntax does not work, you should just wrap it in any layout component doesnt need to be a fieldset
WrkL
WrkLOP2y ago
thanks, is there any read only field like placeholder that accept dot syntax ?
Dan Harrin
Dan Harrin2y ago
Placeholder::make('name')->content(fn ($record) => $record->relationship->column)
Want results from more Discord servers?
Add your server