user image

Mahmoud Santos
Published in : 2022-02-23

How can I validate recaptcha in Livewire class ??

Laravel

Hello guys, Please anyone can help me to do Recaptcha in the Livewire class?

I recently moved my contact form to a livewire component and everything works except my google Recaptcha it no longer works.

// Validate contact info
       $this->validate([
           'name' => 'required|min:4|max:30',
           'email' => 'required|email',
           'subject' => 'required|min:5|max:100',
           'message' => 'required|min:30|max:500',
           'g-recaptcha-response' => config('services.recaptcha.key') ? 'required|recaptcha' : 'nullable',
       ]);

component form

<!-- google recaptcha -->
  @if(config('services.recaptcha.key'))
        <div >
          <div wire:model.defer="g-recaptcha-response" 
          data-sitekey="{{config('services.recaptcha.key')}}">
          </div>
          @error('g-recaptcha-response')
            <span role="alert">
              <strong>{{ $message }}</strong>
            </span>
          @enderror
        </div>
      @endif

 

Comments

Yasen Sayed Date : 2022-02-23

Best answers

8

Best answers

8

If you know Arabic I made a small video to describe how you can use it.

You should follow the next steps in the video, I hope these are will help you.

 

https://www.youtube.com/watch?v=TFJCHny_VgU&ab_channel=LARATRICKS

Mahmoud Santos Date : 2022-02-23

Thank you, that was really helpful 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2
What's the best approach to use Elasticsearch with Larave?
Publish date: 2022-02-21 | Comments: 2
Laravel clear cache files manually
Publish date: 2022-03-02 | Comments: 2
[solved] SQLSTATE[42000]: Syntax error or access violation
Publish date: 2022-01-20 | Comments: 2