PHPackages                             superpx-cn/laravel-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. superpx-cn/laravel-captcha

ActivePackage[Authentication &amp; Authorization](/categories/authentication)

superpx-cn/laravel-captcha
==========================

Laravel Captcha Package

1.0.2(3y ago)147MITPHPPHP ^7.2|^8.0

Since Aug 13Pushed 3y agoCompare

[ Source](https://github.com/SuperPx-CN/laravel-captcha)[ Packagist](https://packagist.org/packages/superpx-cn/laravel-captcha)[ Docs](https://github.com/SuperPx-CN/laravel-captcha)[ RSS](/packages/superpx-cn-laravel-captcha/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Laravel 验证码
===========

[](#laravel-验证码)

支持 Laravel 5/6/7/8/9

一个简单的Laravel 图形验证码服务提供商。

预览
--

[](#预览)

[![Preview](https://camo.githubusercontent.com/5796b984677c086025788097a4f9f89701595234cb98a23c7276c4ea5424c6ef/68747470733a2f2f696d6167652e6962622e636f2f6b5a784d4c6d2f696d6167652e706e67)](https://camo.githubusercontent.com/5796b984677c086025788097a4f9f89701595234cb98a23c7276c4ea5424c6ef/68747470733a2f2f696d6167652e6962622e636f2f6b5a784d4c6d2f696d6167652e706e67)

- [Laravel Captcha](#captcha-for-laravel-5-6-7)
    - [预览](#preview)
    - [Installation](#installation)
    - [Usage](#usage)
    - [Configuration](#configuration)
        - [Custom settings:](#custom-settings)
        - [Disable validation:](#disable-validation)
    - [Example Usage](#example-usage)
        - [Session Mode:](#session-mode)
        - [Stateless Mode:](#stateless-mode)
- [Return Image](#return-image)
- [Return URL](#return-url)
- [Return HTML](#return-html)
- [To use different configurations](#to-use-different-configurations)
    - [Links](#links)

安装
--

[](#安装)

使用 composer 安装

```
composer require superpx-cn/laravel-captcha

```

使用
--

[](#使用)

To use the Captcha Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

Find the `providers` key in `config/app.php` and register the Captcha Service Provider.

```
    'providers' => [
        // ...
        'Mews\Captcha\CaptchaServiceProvider',
    ]
```

for Laravel 5.1+

```
    'providers' => [
        // ...
        Mews\Captcha\CaptchaServiceProvider::class,
    ]
```

Find the `aliases` key in `config/app.php`.

```
    'aliases' => [
        // ...
        'Captcha' => 'Mews\Captcha\Facades\Captcha',
    ]
```

for Laravel 5.1+

```
    'aliases' => [
        // ...
        'Captcha' => Mews\Captcha\Facades\Captcha::class,
    ]
```

Configuration
-------------

[](#configuration)

### Custom settings:

[](#custom-settings)

To use your own settings, publish config.

`$ php artisan vendor:publish`

`config/captcha.php`

```
return [
    'default'   => [
        'length'    => 5,
        'width'     => 120,
        'height'    => 36,
        'quality'   => 90,
        'math'      => true,  //Enable Math Captcha
        'expire'    => 60,    //Captcha expiration
    ],
    // ...
];
```

### Disable validation:

[](#disable-validation)

To disable the captcha validation use `CAPTCHA_DISABLE` environment variable. e.g. **.env** config:

```
CAPTCHA_DISABLE=true
```

Example Usage
-------------

[](#example-usage)

### Session Mode:

[](#session-mode)

```
    // [your site path]/Http/routes.php
    Route::any('captcha-test', function() {
        if (request()->getMethod() == 'POST') {
            $rules = ['captcha' => 'required|captcha'];
            $validator = validator()->make(request()->all(), $rules);
            if ($validator->fails()) {
                echo 'Incorrect!';
            } else {
                echo 'Matched :)';
            }
        }

        $form = '';
        $form .= '';
        $form .= '' . captcha_img() . '';
        $form .= '';
        $form .= 'Check';
        $form .= '';
        return $form;
    });
```

### 无状态模式:

[](#无状态模式)

你可以使用 助手函数 `captcha()` 来生成一个验证码 `captcha()` 方法将会返回一个数组，其中包含了：

- sensitive
- key: 验证码的标识
- img: 验证码的 `base64`编码

并且使用次方法检查验证码

```
    // key is the one that you got from json response
    // fix validator
    // $rules = ['captcha' => 'required|captcha_api:'. request('key')];
    $rules = ['captcha' => 'required|captcha_api:'. request('key') . ',math'];
    $validator = validator()->make(request()->all(), $rules);
    if ($validator->fails()) {
        return response()->json([
            'message' => 'invalid captcha',
        ]);

    } else {
        //do the job
    }
```

Return Image
============

[](#return-image)

```
captcha();
```

or

```
Captcha::create();
```

Return URL
==========

[](#return-url)

```
captcha_src();
```

or

```
Captcha::src('default');

```

Return HTML
===========

[](#return-html)

```
captcha_img();
```

or

```
Captcha::img();
```

To use different configurations
===============================

[](#to-use-different-configurations)

```
captcha_img('flat');

Captcha::img('inverse');
```

etc.

Based on [Intervention Image](https://github.com/Intervention/image)

^\_^

Links
-----

[](#links)

- [Intervention Image](https://github.com/Intervention/image)
- [L5 Captcha on Github](https://github.com/mewebstudio/captcha)
- [L5 Captcha on Packagist](https://packagist.org/packages/mews/captcha)
- [For L4 on Github](https://github.com/mewebstudio/captcha/tree/master-l4)
- [License](http://www.opensource.org/licenses/mit-license.php)
- [Laravel website](http://laravel.com)
- [Laravel Turkiye website](http://www.laravel.gen.tr)
- [MeWebStudio website](http://www.mewebstudio.com)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~194 days

Total

2

Last Release

1174d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84d7c320accb0f9c66ec2e4d59704e9cccca1d1c100ffb2fb8b7f4f217007667?d=identicon)[SuperPx-CN](/maintainers/SuperPx-CN)

---

Top Contributors

[![mewebstudio](https://avatars.githubusercontent.com/u/2125733?v=4)](https://github.com/mewebstudio "mewebstudio (132 commits)")[![mauris](https://avatars.githubusercontent.com/u/996939?v=4)](https://github.com/mauris "mauris (33 commits)")[![mwllgr](https://avatars.githubusercontent.com/u/25794895?v=4)](https://github.com/mwllgr "mwllgr (10 commits)")[![sineld](https://avatars.githubusercontent.com/u/445349?v=4)](https://github.com/sineld "sineld (7 commits)")[![saidbakr](https://avatars.githubusercontent.com/u/467554?v=4)](https://github.com/saidbakr "saidbakr (5 commits)")[![SuperPx-CN](https://avatars.githubusercontent.com/u/38307045?v=4)](https://github.com/SuperPx-CN "SuperPx-CN (4 commits)")[![jxlwqq](https://avatars.githubusercontent.com/u/2421068?v=4)](https://github.com/jxlwqq "jxlwqq (3 commits)")[![Sergej-Tihonov](https://avatars.githubusercontent.com/u/15265981?v=4)](https://github.com/Sergej-Tihonov "Sergej-Tihonov (3 commits)")[![hutushen222](https://avatars.githubusercontent.com/u/352215?v=4)](https://github.com/hutushen222 "hutushen222 (3 commits)")[![khalilst](https://avatars.githubusercontent.com/u/9103966?v=4)](https://github.com/khalilst "khalilst (3 commits)")[![Assmay](https://avatars.githubusercontent.com/u/18699209?v=4)](https://github.com/Assmay "Assmay (2 commits)")[![farzinghanbari](https://avatars.githubusercontent.com/u/14145192?v=4)](https://github.com/farzinghanbari "farzinghanbari (2 commits)")[![jp7anderson](https://avatars.githubusercontent.com/u/9416588?v=4)](https://github.com/jp7anderson "jp7anderson (2 commits)")[![Lin-H](https://avatars.githubusercontent.com/u/7029374?v=4)](https://github.com/Lin-H "Lin-H (1 commits)")[![marktan93](https://avatars.githubusercontent.com/u/4466554?v=4)](https://github.com/marktan93 "marktan93 (1 commits)")[![lddsb](https://avatars.githubusercontent.com/u/20765867?v=4)](https://github.com/lddsb "lddsb (1 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (1 commits)")[![mweghorst](https://avatars.githubusercontent.com/u/9582326?v=4)](https://github.com/mweghorst "mweghorst (1 commits)")[![jeffwudev](https://avatars.githubusercontent.com/u/18082263?v=4)](https://github.com/jeffwudev "jeffwudev (1 commits)")[![naneri](https://avatars.githubusercontent.com/u/5573469?v=4)](https://github.com/naneri "naneri (1 commits)")

---

Tags

captchaLaravel Securitylaravel-captcha

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/superpx-cn-laravel-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/superpx-cn-laravel-captcha/health.svg)](https://phpackages.com/packages/superpx-cn-laravel-captcha)
```

###  Alternatives

[mews/captcha

Laravel 5/6/7/8/9/10/11/12 Captcha Package

2.6k5.5M84](/packages/mews-captcha)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
