Skip to content

Instantly share code, notes, and snippets.

@devhoussam
Created February 7, 2021 16:08
Show Gist options
  • Save devhoussam/b4ad57415c86a6dc05a7bbdd40bce97f to your computer and use it in GitHub Desktop.
Save devhoussam/b4ad57415c86a6dc05a7bbdd40bce97f to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire;
use App\Models\User;
use Livewire\Component;
class ExampleForm extends Component
{
public $name = '';
public $email = '';
public $isDisabled = false;
protected $rules = [
'name' => 'required|min:6',
'email' => 'required|email',
];
public function updated($propertyName)
{
$this->validateOnly($propertyName);
if (empty($propertyName)) {
$this->isDisabled = false;
}
}
public function submitForm()
{
$validatedData = $this->validate();
User::create($validatedData);
}
public function render()
{
return view('livewire.example-form');
}
}
<form wire:submit.prevent="submitForm">
<input type="text" wire:model="name">
@error('name') <span class="error">{{ $message }}</span> @enderror
<input type="email" wire:model="email">
@error('email') <span class="error">{{ $message }}</span> @enderror
<button type="submit" disabled="{{ $isDisabled }}">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment