ashraam/laravel-capjs
Composer 安装命令:
composer require ashraam/laravel-capjs
包简介
A simple package to integrate Cap.js, an hCaptcha-like open source challenge, into your Laravel application.
README 文档
README
A simple package to integrate Cap.js, an hCaptcha-like open source challenge, into your Laravel application.
This package provides a simple way to integrate Cap.js into your Laravel application.
Installation
You can install the package via composer:
composer require ashraam/laravel-capjs
Configuration
First, you need to publish the configuration file:
php artisan vendor:publish --provider="Ashraam\\Capjs\\CapjsServiceProvider" --tag="config"
This will create a config/capjs.php file in your application. You can then add your Cap.js credentials to your .env file:
CAPJS_HOST=
CAPJS_KEY=
CAPJS_SECRET=
Usage
Blade Directive
To include the Cap.js script, you can use the @capjsScript directive in your Blade template:
<!DOCTYPE html> <html> <head> ... @capjsScript </head> <body> ... </body> </html>
Facade
You can also get the script tag from the Capjs facade:
{!! Capjs::script() !!}
Blade Component
To display the Cap.js widget, you can use the <x-capjs-widget> component:
<form method="POST" action="/register"> @csrf ... <x-capjs-widget /> @error('cap-token') {{ $message }} @enderror ... <button type="submit">Register</button> </form>
The component also accepts an optional id and locale attribute:
<x-capjs-widget id="my-capjs-widget" locale="fr" />
Events
The component dispatches custom events such as solve, error, reset, and progress. You can attach an event listener to the widget to capture these events.
For instance, to get the token when the captcha is solved, you would use the following JavaScript code:
const widget = document.querySelector("#my-capjs-widget"); widget.addEventListener("solve", function (e) { const token = e.detail.token; // Handle the token as needed });
Styling
You can customize the appearance of the widget by overriding the default CSS variables.
cap-widget { --cap-background: #fdfdfd; --cap-border-color: #dddddd8f; --cap-border-radius: 14px; --cap-widget-height: 30px; --cap-widget-width: 230px; --cap-widget-padding: 14px; --cap-gap: 15px; --cap-color: #212121; --cap-checkbox-size: 25px; --cap-checkbox-border: 1px solid #aaaaaad1; --cap-checkbox-border-radius: 6px; --cap-checkbox-background: #fafafa91; --cap-checkbox-margin: 2px; --cap-font: system, -apple-system, "BlinkMacSystemFont", ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", "Ubuntu", "arial", sans-serif; --cap-spinner-color: #000; --cap-spinner-background-color: #eee; --cap-spinner-thickness: 5px; --cap-checkmark: url("data:image/svg+xml,..."); --cap-error-cross: url("data:image/svg+xml,..."); --cap-credits-font-size: 12px; --cap-opacity-hover: 0.8; }
Validation Rule
To validate the Cap.js token, you can use the capjs validation rule:
use Illuminate\Http\Request; public function register(Request $request) { $request->validate([ ... 'cap-token' => ['required', 'capjs'], ... ]); ... }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email romain.bertolucci@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
ashraam/laravel-capjs 适用场景与选型建议
ashraam/laravel-capjs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「captcha」 「laravel」 「hcaptcha」 「ashraam」 「capjs」 「cap.js」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ashraam/laravel-capjs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ashraam/laravel-capjs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ashraam/laravel-capjs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Various captchas that support the mechanism for switching between them in the configuration file
geekk/multi-captcha integration for laravel
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Two Captcha
Integrate hCaptcha validation into your forms.
Multi-provider captcha integration for Filament forms (hCaptcha, reCAPTCHA v2/v3, Turnstile)
统计信息
- 总下载量: 57
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-16