1LARAVEL COMPONENT
2
3class ContactForm extends Component {
4 public $name;
5 public $email;
6 protected $rules = [
7 'name' => 'required|min:6',
8 'email' => 'required|email',
9 ];
10 public function updated($propertyName) {
11 $this->validateOnly($propertyName);
12 }
13 public function saveContact()
14 {
15 $validatedData = $this->validate();
16 Contact::create($validatedData);
17 }
18 }
19
20BLADE
21
22 <form wire:submit.prevent="saveContact">
23 <input type="text" wire:model="name">
24 @error('name') <span class="error">{{ $message }}</span> @enderror
25
26 <input type="text" wire:model="email">
27 @error('email') <span class="error">{{ $message }}</span> @enderror
28
29 <button type="submit">Save Contact</button>
30 </form>