ms41/laravel-captcha13 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ms41/laravel-captcha13

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ms41/laravel-captcha13

包简介

A Laravel 13 compatible CAPTCHA package

README 文档

README

A simple, customizable, and Laravel 13 compatible CAPTCHA package for generating image-based captchas with session-based validation.

This package provides:

  • CAPTCHA image generation
  • Session-based validation
  • Easy Blade integration
  • Configurable size, route, colors, and font
  • Laravel auto-discovery support

Preview

Captcha Example

Add your preview image(s) here after uploading screenshots to your GitHub repository.

Example 1

Captcha Preview 1

Example 2

Captcha Preview 2

Requirements

PHP 8.3+ Laravel 13+ Installation

Install the package via Composer:

composer require ms41/laravel-captcha13

Package Auto-Discovery

The package supports Laravel package auto-discovery.

So after installation, you do not need to manually register the service provider or alias.

Publish Configuration

If you want to customize the package configuration, publish the config file:

php artisan vendor:publish --tag=captcha13-config

This will publish:

config/captcha.php

Basic Usage in Blade

You can render the captcha image in any Blade view like this:

{!! Captcha::img() !!}

Basic Form Example

@csrf
<div>
    {!! Captcha::img() !!}
</div>

<div style="margin-top: 10px;">
    <input type="text" name="captcha" placeholder="Enter captcha">
</div>

<button type="submit" style="margin-top: 10px;">Submit</button>

Validation Example (Controller)

 use Illuminate\Http\Request;
 use Shahid\Captcha\Facades\Captcha;

 public function submit(Request $request)
{
    $request->validate([
        'captcha' => ['required'],
    ]);

    if (!Captcha::validate($request->captcha)) {
        return back()
            ->withErrors(['captcha' => 'Invalid captcha entered.'])
            ->withInput();
    }

    return back()->with('success', 'Captcha verified successfully!');
}

Validation Example (Route Closure)

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Shahid\Captcha\Facades\Captcha;

Route::get('/captcha-test', function () {
    return view('captcha-test');
});

Route::post('/captcha-test', function (Request $request) {
    $request->validate([
        'captcha' => ['required'],
    ]);

    if (!Captcha::validate($request->captcha)) {
        return back()
            ->withErrors(['captcha' => 'Invalid captcha entered.'])
            ->withInput();
    }

    return back()->with('success', 'Captcha verified successfully!');
})->name('captcha.test.submit');

Facade Usage

The package provides a facade:

use Shahid\Captcha\Facades\Captcha;

Available Methods

Render captcha image HTML

Captcha::img();

Validate captcha input

Captcha::validate($request->captcha);

Configuration

After publishing the config file, you can customize the package using:

config/captcha.php

Default Configuration

<?php

return [
    'length' => 6,
    'width' => 200,
    'height' => 60,
    'background' => '#f9fafb',
    'text_color' => '#374151',
    'session_key' => 'captcha_code',
    'route' => 'captcha/image',
    'font' => null,
];

Configuration Options

Notes

  • The package uses session-based validation, so the captcha image route must work under the web middleware.
  • A new captcha is generated whenever the captcha image is refreshed.
  • The package appends a timestamp query parameter to the image URL to prevent browser caching.
  • If a custom font is not provided, the package uses its internal default font automatically.

Recommended Package Route

If you want to understand how the package route works internally, it should use the web middleware because the package relies on sessions:

Route::middleware('web')->group(function () {
    Route::get('captcha/image', [CaptchaController::class, 'image'])
        ->name('captcha13.image');
});

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固