nguyentranchung / laravel-google-recaptcha
Google reCAPTCHA v2
2.0.0
2018-11-18 01:36 UTC
Requires
- guzzlehttp/guzzle: ^6.3
This package is auto-updated.
Last update: 2024-09-04 19:18:07 UTC
README
安装
composer require nguyentranchung/laravel-google-recaptcha
在.env文件中
GOOGLE_RECAPTCHA_KEY="your-google-recaptcha-key"
GOOGLE_RECAPTCHA_SECRET="your-google-recaptcha-secret"
在视图中
<script src="https://www.google.com/recaptcha/api.js" async defer></script> <div class="g-recaptcha" data-sitekey="{{ config('google-recaptcha.key') }}"></div>
在控制器中
class PostController extends Controller { public function store(Request $request) { $datas = $request->validate([ // ... 'g-recaptcha-response' => 'required|recaptcha', ]); } } // hoặc ở trong FormRequest class PostStoreRequest extends FormRequest { /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ // ... 'g-recaptcha-response' => 'required|recaptcha', ]; } }