Answers for "Laravel Livewire Realtime validation"

PHP
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

Code answers related to "Laravel Livewire Realtime validation"

Browse Popular Code Answers by Language