Hcaptcha & Google ReCaptcha Solution for Laravel Framework

Overview

Poster Laravel Captcha

Laravel Captcha

StyleCI Status Build Status Version Total Downloads

Laravel Captcha is a wrapper around HCaptcha & Google Recaptcha. It provides very easy-to-use Facade, Validation Rule, and blade directives.

Installation

Requires PHP 7.3+

  1. Install via Composer:
composer require rahul900day/laravel-captcha
  1. Publish the config file with:
php artisan vendor:publish --tag="captcha-config"
  1. Add required configuration to .env file:
CAPTCHA_DRIVER=hCaptcha
CAPTCHA_SITE_KEY="{Your Site Key}"
CAPTCHA_SECRET_KEY="{Your Site Secret}"

Don't know how to get the Site Key or Site Secret ?
Read HCaptcha or ReCaptcha Docs.

Configuration

Laravel Captcha supports very different customizations like theme, language, size. Just add these configurations to your .env file to customize.

Supported ENV Variables

Variable Default Description
CAPTCHA_DRIVER hCaptcha Default Captcha driver
Supported:hCaptcha, reCaptcha
CAPTCHA_SITE_KEY '' The Site Key.
HCaptcha Docs: https://docs.hcaptcha.com/configuration
ReCaptcha Docs: https://developers.google.com/recaptcha/docs/display
CAPTCHA_SECRET_KEY '' The Site Secret.
HCaptcha Docs: https://docs.hcaptcha.com/configuration
ReCaptcha Docs: https://developers.google.com/recaptcha/docs/display
CAPTCHA_LOCALE en The Captcha localization code.
HCaptcha Supported Codes: https://docs.hcaptcha.com/languages
Recaptcha Supported Codes: https://developers.google.com/recaptcha/docs/language
CAPTCHA_THEME light The Captcha checkbox theme.
Supported: light, dark
CAPTCHA_SIZE normal The Captcha checkbox size.
Supported: normal, compact

Note: Laravel Captcha Does not support ReCaptcha V3

Usage

Displaying Captcha

Laravel Captcha Provide two blade directives for importing required javascript and displaying the captcha itself.

@captcha_container ">
<head>
    @captcha_js
head>
<body>
  <form action="" method="post">
      @captcha_container
  form>
body>

The @captcha_js Directive

The @captcha_js directive allows you to inject the javascript for captcha. You can also pass additional language parameter into it.

@captcha_js('fr')

Read the HCaptcha & ReCaptcha docs to get the full language code list.

The @captcha_container Directive

The @captcha_container directive provides the captcha checkbox for your form. it also accepts two parameters theme & size respectively.

@captcha_container('light', 'compact')

Validation of Captcha

Laravel Captcha provides a very beautiful API to deal with captcha validation. In your Controller or FormRequest you can just add this code to validate the captcha.

use Rahul900day\Captcha\Facades\Captcha;
use Rahul900day\Captcha\Rules\Captcha as CaptchaRule;
use Illuminate\Support\Facades\Validator;

Validator::make($request, [
   Captcha::getResponseName() => [
       'required', 
        new CaptchaRule(),
   ],
]);

Testing

With Laravel Captcha you can write tests very easily. The Captcha facade's fake method allows you to fake the Captcha Validation for the current request.

use Rahul900day\Captcha\Facades\Captcha;
use Rahul900day\Captcha\Rules\Captcha as CaptchaRule;
use Illuminate\Support\Facades\Validator;

Captcha::fake();

// If $request is an actual request or a request array
$validation = Validator::make($request, [
   Captcha::getResponseName() => [
       'required', 
        new CaptchaRule(),
   ],
]);

$this->assertTrue(! $validation->fails()) // This is always going to pass.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(1.0.1)
Owner
Rahul Dey
Laravel, Wordpress & Vue.Js Developer. I have ideas to build awesome stuff. Happy Coding... 😊
Rahul Dey
PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

reCAPTCHA PHP client library reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the s

Google 3.3k Dec 23, 2022
A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

Big_Cake 2 Jan 25, 2022
Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Ogundiran Adewale Charles 2 Jul 27, 2022
A modern solution for running Laravel Horizon with a CRON-based supervisor.

A modern solution for running Laravel Horizon with a cron-based supervisor This Laravel package automatically checks every three minutes if your Larav

Ralph J. Smit 31 Dec 9, 2022
LaravelFly is a safe solution to speeds up new or old Laravel 5.5+ projects, with preloading and coroutine, while without data pollution or memory leak

Would you like php 7.4 Preloading? Would you like php coroutine? Today you can use them with Laravel because of Swoole. With LaravalFly, Laravel will

null 456 Dec 21, 2022
A flexible, seamless and easy to use multitenancy solution for Laravel

Main: Develop: Tenanted Laravel A flexible, seamless and easy to use multitenancy solution for Laravel This package is currently under development. Ch

Tenanted Laravel 12 May 29, 2023
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.

Introduction A simple drop-in solution for providing UUID support for the IDs of your Eloquent models. Both v1 and v4 IDs are supported out of the box

GoldSpec Digital 501 Jan 4, 2023
This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT.

This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT. Two solutions are proposed, the first is a brute force approach while the other is an improved time complexity solution.

null 3 May 23, 2022
Open Source Invoicing Solution for Individuals & Businesses

Introduction Crater is an open-source web & mobile app that helps you track expenses, payments & create professional invoices & estimates. Web Applica

Crater Invoice 6.7k Jan 4, 2023
Simple solution for form request validation on lumen.

Form Request Validation for Lumen This small package contains a laravel-like solution for request form validation. Contents Form Request Validation fo

Samuel Nunes de Souza 5 Nov 4, 2022
Jumpstart your web development journey with the HALT Stack Starter Kit, a one-command solution for creating dynamic, scalable, and clean web applications.

Welcome to the HALT Stack Starter Kit! This kit is designed to help you kickstart your web development projects using the HALT Stack, a powerful combi

HALT Stack 6 Jun 7, 2023
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022
Manage self-hosted Google Fonts in Laravel apps

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users. To load fonts in your application, register a Google Fonts embed URL and load it with the @googlefonts Blade directive.

Spatie 386 Dec 19, 2022
Automatically disable Google's FLoC in Laravel apps

Automatically disable Google's FLoC in Laravel apps This package will automatically disable Google's FLoC. Support us We invest a lot of resources int

Spatie 68 Oct 21, 2022
Google Cloud Storage filesystem driver for Laravel

Google Cloud Storage filesystem driver for Laravel Google Cloud Storage filesystem driver for Laravel. This started as a fork from Superbalist/laravel

Spatie 88 Dec 16, 2022
Laravel real-time CRUD using Google Firebase.

Laravel real-time CRUD using Google Firebase.

Fadi Mathlouthi 1 Oct 22, 2021
a Google API v3 wrapper for Laravel 4.x

A Google API v3 wrapper for Laravel 4 This package enables a Laravel flavoured way to manage Google services through its API interface (v3) Installati

null 4 Nov 29, 2022
Laravel Google Maps Package

Laravel Google Maps This repo aims to use google map features in laravel 5.x. It is easy to use and flexible, you can just install this package and en

Farhan Wazir 146 Nov 29, 2022
An easy way to integrate Google Maps with Laravel

An easy way to integrate Google Maps with Laravel For Laravel 5.x, check version 2.35.1 For Laravel 4.x, check version 1.27.0 Think of Googlmapper as

Bradley Cornford 450 Nov 29, 2022