Validation | Laravel Livewire

PHOTO EMBED

Mon May 27 2024 05:49:55 GMT+0000 (Coordinated Universal Time)

Saved by @tsesang

 1class ContactForm extends Component
 2{
 3    public $name;
 4    public $email;
 5 
 6    protected $rules = [
 7        'name' => 'required|min:6',
 8        'email' => 'required|email',
 9    ];
10 
11    public function updated($propertyName)
12    {
13        $this->validateOnly($propertyName);
14    }
15 
16    public function saveContact()
17    {
18        $validatedData = $this->validate();
19 
20        Contact::create($validatedData);
21    }
22}
content_copyCOPY

https://laravel-livewire.com/docs/2.x/input-validation