ajnorman/turnstile-laravel-middleware 问题修复 & 功能扩展

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

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

ajnorman/turnstile-laravel-middleware

最新稳定版本:1.0.0-beta.3

Composer 安装命令:

composer require ajnorman/turnstile-laravel-middleware

包简介

A package that adds middleware to check for bots using Cloudflare Turnstile

README 文档

README

⚠️ Documentation is incomplete and may be inaccurate. ⚠️

Static Badge Static Badge

Table of Contents

Introduction

This package provides a piece middleware for Laravel that integrates with Cloudflare Turnstile to protect your application from unwanted bots.

Requirements

  • PHP >= 8.2
  • Laravel >= 11.x
  • A Cloudflare account with Turnstile enabled and a site_key and secret_key generated. View the Cloudflare Turnstile documentation for more information.

Installation

You can install the package via composer:

composer require aj-norman/turnstile-laravel-middleware

Add the following environment variables to your .env file:

CF_TURNSTILE_SITE_KEY=<your-site-key>
CF_TURNSTILE_SECRET_KEY=<your-secret-key>

(Optional) Publish the configuration file:

php artisan vendor:publish --provider="AJNorman\Turnstile\TurnstileServiceProvider" --tag="config"

If you customize the configuration file, you may need to manually update the config/turnstile.php file in the future if the package is updated.

Add 'turnstile' => AJNorman\Turnstile\Middleware\TurnstileMiddleware::class middleware to the alias() array within the withMiddleware() method in your bootstrap/app.php file:

return Application::configure(basePath: dirname(__DIR__))
    //...
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->alias([
            //...
            'turnstile' => \AJNorman\Turnstile\Middleware\TurnstileMiddleware::class,
        ]);
    })
    //...
    ->create();

The 'turnstile' key can be changed to any key you prefer.

Usage

You can apply the Turnstile middleware to any route or group of routes by adding 'turnstile' to the middleware array:

Route::post('/protected-route', function () {
    return 'This route is protected by Turnstile!';
})->middleware('turnstile');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-26