首页 > 解决方案 > Laravel 上的 ReCaptcha

问题描述

我在注册控制器中有 ReCaptcha,我想把它放在登录控制器中,比如

<?php

namespace App\Http\Middleware;

use App\Rules\Captcha;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use App\Rules\Captcha;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }

    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            'g-recaptcha-response' => new Captcha(),
        ]);
    }
}

但是我收到一个错误Cannot use App\Rules\Captcha as Captcha because the name is already in use 是否有其他方法可以将 ReCaptcha 放入 reg 和 log 中?

标签: laravelrecaptcha

解决方案


您的文件开头有两次以下行:

use App\Rules\Captcha;

推荐阅读