nguyentranchung/laravel-google-recaptcha

Google recaptcha v2

2.0.0 2018-11-18 01:36 UTC

This package is auto-updated.

Last update: 2024-04-04 18:25:36 UTC


README

Cài đặt

composer require nguyentranchung/laravel-google-recaptcha

In .env

GOOGLE_RECAPTCHA_KEY="your-google-recaptcha-key"
GOOGLE_RECAPTCHA_SECRET="your-google-recaptcha-secret"

In view

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="{{ config('google-recaptcha.key') }}"></div>

In controller

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',
        ];
    }
}