-
app/Traits/HCaptcha.php
Open in GitHubtrait HCaptcha { public function validateResponse($response) { $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query(array('secret' => config('app.hcaptcha_secret_key'), 'response' => $response))); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $result = json_decode(curl_exec($verify)); return $result->success; } }
-
app/Http/Controllers/Store/ContactController.php
Open in GitHubuse App\Traits\HCaptcha; class ContactController extends Controller { use HCaptcha; // public function store(Request $request) { $request->validate([ 'email' => 'required|email|max:255', 'name' => 'required|string|min:3|max:255', 'subject' => 'required|string|min:20|max:255', 'message' => 'required|string|min:100|max:5000', ]); if (!$this->validateResponse($request->input('h-captcha-response'))) { $request->flashExcept('h-captcha-response'); return back()->with('danger_msg', 'Please solve the captcha challenge again.'); } // } } }
-
resources/views/store/contact.blade.php
Open in GitHub// @include('layouts.store.hcaptcha') //
-
resources/views/layouts/store/hcaptcha.blade.php
Open in GitHub<div class="form-group"> <div class="h-captcha" data-sitekey="{{ config('app.hcaptcha_site_key') }}" @if (config('app.dark_mode')) data-theme="dark" @endif></div> </div>