The issue you're experiencing with the Livewire component not updating the nested input field is likely due to the fact that the wire:model directive is not being applied directly to the <input> element within your custom Blade component. Livewire requires the wire:model directive to be directly on the input element to properly bind the data.
To resolve this, you need to ensure that the wire:model directive is passed down to the actual <input> element within your custom component. Here's how you can modify your component to achieve this:
-
Update your Blade component to accept additional attributes and pass them to the
<input>element. -
Use the
@propsdirective to allow passing of attributes likewire:model.
Here's how you can modify your component:
@props([
'autoComplete' => 'off',
'label' => 'label',
'required' => false,
'type' => 'text',
'errorMessages' => [],
'step' => '.1',
])
<label {{ $attributes->merge(['class' => 'form-control w-full']) }}>
<div class='label'>
<span class='label-text'>{{ $label }}</span>
</div>
<input {{ $attributes->whereStartsWith('wire:model') }} class="input input-bordered w-full" type='{{ $type }}'
@isset($step)
step="{{ $step }}"
@endif autoComplete='{{ $autoComplete }}'
@required($required) />
<x-input-error :messages="$errorMessages" class="mt-2" />
</label>
In this updated version, the {{ $attributes->whereStartsWith('wire:model') }} line ensures that any wire:model attribute passed to the component is applied directly to the <input> element.
Now, when you use your component, you can pass the wire:model directive like this:
<section>
<x-input-field wire:model="foodName" :errorMessages="$errors->get('foodName')"
label="{{ __('Food Name') }}" placeholder="{{ __('type food name') }}" />
</section>
This should ensure that the foodName property is properly bound to the input field, and any updates to foodName will reflect in the input field as expected.