Answers for "validation real time livewire and fails"

1

livewire validation

$validatedData = $this->validate([
            'name' => 'required|min:6',
            'email' => 'required|email',
        ]);
Posted by: Guest on June-28-2021
0

Laravel Livewire Realtime validation

LARAVEL COMPONENT

class ContactForm extends Component { 
               public $name; 
               public $email;
               protected $rules = [
                 'name' => 'required|min:6',
                 'email' => 'required|email',
               ];
               public function updated($propertyName) {
                 $this->validateOnly($propertyName);
               }
               public function saveContact()
               {
                 $validatedData = $this->validate();
                 Contact::create($validatedData);
               }
             }

BLADE

        <form wire:submit.prevent="saveContact">
          <input type="text" wire:model="name">
          @error('name') <span class="error">{{ $message }}</span> @enderror

          <input type="text" wire:model="email">
          @error('email') <span class="error">{{ $message }}</span> @enderror

          <button type="submit">Save Contact</button>
      </form>
Posted by: Guest on September-23-2021

Browse Popular Code Answers by Language