phplaravel-livewirelaravel-7

Laravel Livewire how to validate array data


I try to validate array when form submitted as

<input type="text" class="form-control" wire:model.lazy="data.name" placeholder="name">
    //at livewire component class
    $data = [
        'name' => 'someValue',
        'phone' => 'someValue',
        'email' => 'someValue'
    ]

I try this

    Validator::make($this->data,[
      'name' => 'required',
       ...
    ])->validate();

but not working, please help me.


Solution

  • You can validate using the same syntax as you have used in wire:model:

    $this->validate([
        'data.name' => ['required'],
    ]);