I’m wondering how I can implement the buzz/laravel-google-captcha package in livewire real-time validation rules?
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class ExampleForm extends Component
{
public $email = '';
public $password = '';
protected $rules = [
'email' => 'required|email',
'password' => 'required|min:6',
// 'g-recaptcha-response' => 'required|captcha',
];
public function messages()
{
return [
];
}
public function updated($propertyName)
{
$this->validateOnly($propertyName);
}
public function submitForm()
{
$validatedData = $this->validate();
Example::create($validatedData);
}
public function render()
{
return view('livewire.example-form');
}
}
.blade.php
<form wire:submit.prevent="submitForm">
<input type="email" wire:model="email">
@error('email') <span class="error">{{ $message }}</span> @enderror
<input type="password" wire:model="password">
@error('password') <span class="error">{{ $message }}</span> @enderror
{!! Captcha::display() !!}
@error('g-recaptcha-response') <span class="error">{{ $message }}</span> @enderror
<button type="submit">Submit</button>
</form>