Search code examples
phplaravelvalidationlaravel-livewire

Livewire array validation not rendering the errors


Livewire validation of array inputs is not rendering

class TravelDetail extends SlideOver
{
    public $existed_visa_name = []; //an array input
}

protected $rules = [
        'existed_visa_name.*' => 'required|min:6'
    ];

public function save()
{

    $this->validate(); // validating here
    return;
}

blade file

<input type="text" class="form-control form-control-solid ps-13" placeholder="{{ __('Visa Name') }}" wire:model.defer="existed_visa_name.{{ $key }}">
@error('existed_visa_name.{{ $key }}') <span class="error">{{ $message }}</span> @enderror

<!--It is in the loop and $key = 0 -->

Solution

  • Try this instead. Let me know if it works. @error('existed_visa_name.' . $key). Source Laracast question