Laravel 上的验证码

ReCaptcha on Laravel

我在注册控制器中有 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 放入注册和日志中吗?

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

use App\Rules\Captcha;