如何在页面顶部显示 laravel 登录限制消息?

How to show laravel login throttle message at the top of the page?

默认情况下 Laravel 在 email/username 字段下方显示限制消息 "Too many login attempts" 消息。

如何在页面顶部显示此消息。

在您的 `LoginController

中覆盖 sendLockoutResponse
protected function sendLockoutResponse(Request $request)
{
    $seconds = $this->limiter()->availableIn(
        $this->throttleKey($request)
    );

    throw ValidationException::withMessages([
        'throttle' => [Lang::get('auth.throttle', ['seconds' => $seconds])],
    ])->status(Response::HTTP_TOO_MANY_REQUESTS);
}

您需要导入以下内容

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Lang;
use Illuminate\Validation\ValidationException;

然后在您的视图中,在您需要限制消息的地方添加以下内容

如果您的 Laravel 版本是 5.8.12 或更高版本

@error('throttle')
    <strong>{{ $message }}</strong>
@enderror

其他

@if ($errors->has('throttle'))
    <strong>{{ $errors->first('throttle') }}</strong>
@endif