Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Arcaptcha Laravel Laravel Package

arcaptcha/arcaptcha-laravel

Laravel integration for ArCaptcha (PHP 7.3+). Install via Composer, publish config, set ARCAPTCHA site/secret keys in .env, embed the widget in Blade forms, and verify the submitted token server-side using the provided service/facade.

View on GitHub
Deep Wiki
Context7

Laravel ArCaptcha Package

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Laravel Package for the ArCaptcha This package supports PHP 7.3+.

For PHP integration you can use mohammadv184/arcaptcha package.

List of contents

Installation

You can install the package via composer:

composer require arcaptcha/arcaptcha-laravel

Laravel 5.5 (or greater) uses package auto-discovery, so doesn't require you to manually add the Service Provider, but if you don't use auto-discovery ArCaptchaServiceProvider must be registered in config/app.php:

'providers' => [
    ...
    Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider::class,
];

You can use the facade for shorter code. Add ArCaptcha to your aliases:

'aliases' => [
    ...
    'ArCaptcha' => Mohammadv184\ArCaptcha\Laravel\Facade\ArCaptcha::class,
];

Configuration

Publish package

Create config/arcaptcha.php configuration file using the following artisan command:

php artisan vendor:publish --provider="Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider"

Set the environment

Open .env file and set ARCAPTCHA_SITE_KEY and ARCAPTCHA_SECRET_KEY:

# in your .env file
ARCAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
ARCAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY

# Optional: Default returned value from verify function
# when there is an Network or any other unexpected issue.
ARCAPTCHA_VERIFY_EXCEPTION_VALUE=true

Customize error message

Before starting please add the validation message to resources/lang/[LANG]/validation.php file

return [
    ...
    'arcaptcha' => 'Hey!!! :attribute is wrong!',
];

How to use

How to use ArCaptcha in Laravel.

Embed Script in Blade

Insert @arcaptchaScript blade directive before closing </head> tag.

You can also use ArCaptcha::getScript().

<!DOCTYPE html>
<html>
  <head>
    ... @arcaptchaScript
  </head>
</html>

Form setup

After you have to insert @arcaptchaWidget blade directive inside the form where you want to use the field arcaptcha-token.

You can also use ArCaptcha::getWidget().

Note : You can pass widget options into getWidget function or arcaptchaWidget directive like this : @arcaptchaWidget(['lang'=>'en'])

To see available options on widget see here

<form>
  @csrf ... @arcaptchaWidget
  <!-- OR -->
  {!! ArCaptcha::getWidget() !!}
  <input type="submit" />
</form>

Verify submitted data

Add arcaptcha to your rules

$validator = Validator::make(request()->all(), [
        ...
        'arcaptcha-token' => 'arcaptcha',
    ]);

    // check if validator fails
    if($validator->fails()) {
        ...
        $errors = $validator->errors();
    }

Invisible mode example

Just try to pass size and callback option to getWidget function. Make sure to define callback function in global scope:

<form>
  {!! ArCaptcha::getWidget([ 'size'=>'invisible','callback'=>'callback']) !!}
  <input type="submit" />

  <script>
    function callback(token) {
      // Challenge is solved! Just submit the form!
    }
  </script>
</form>

Credits

License

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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky