📌  相关文章
📜  recaptcha v3 laravel 8 - PHP (1)

📅  最后修改于: 2023-12-03 15:19:46.871000             🧑  作者: Mango

Recaptcha V3 Laravel 8

Recaptcha V3 is an advanced version of Google's reCAPTCHA technology which is used to verify that users are human and not bots. It uses advanced risk analysis techniques to differentiate between bots and humans. Laravel 8 comes with built-in support for Recaptcha V3, making it easy for developers to integrate it into their applications.

Installation

Installing Recaptcha V3 in Laravel 8 is very easy. You just need to follow these simple steps:

  1. Add the GoogleRecaptcha library to your composer.json file:
composer require google/recaptcha
  1. Next, add the following line to your .env file:
GOOGLE_RECAPTCHA_SECRET=your-secret-key
  1. Finally, add the following line to your config/app.php file:
'providers' => [
    //...
    Revolution\Google\Recaptcha\RecaptchaServiceProvider::class
],

'aliases' => [
    //...
    'Recaptcha' => Revolution\Google\Recaptcha\Facades\Recaptcha::class
]
Usage

To use Recaptcha V3 in your Laravel 8 application, you can simply add the recaptcha validation rule to your validation method:

public function exampleForm(Request $request)
{
    $request->validate([
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:8|confirmed',
        'g-recaptcha-response' => 'required|recaptcha'
    ]);
}

The g-recaptcha-response field must be included in your form for Recaptcha V3 to work. This field will be automatically generated by Recaptcha V3 and will contain the response token.

Conclusion

In conclusion, Recaptcha V3 is a powerful tool that can help you secure your Laravel 8 application against bots and other malicious attacks. With its built-in support for Recaptcha V3, Laravel 8 makes it easy for developers to integrate this technology into their applications. If you want to make your application more secure, Recaptcha V3 is definitely worth considering.