繁体   English   中英

:seconds to:hours in Laravel 油门?

[英]:seconds to :hours in Laravel Throttle?

在我的

resources/lang/en/auth.php

我有这个

<?php

return [

/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| message that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/

'failed' => 'These credentials do not match our records.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',

];

有没有办法编辑油门:seconds到一小时?

前面的错误信息是这样的

Too many login attempts. Please try again in 2 hour(s).

默认情况下,throttle login trait 只给出minutesseconds ,如果你想添加小时,只需覆盖Illuminate\Foundation\Auth\ThrottlesLoginssendLockoutResponse方法,如下所示(在使用AuthenticatesUsers trait 的 LoginController 中):

/**
 * Redirect the user after determining they are locked out.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return void
 *
 * @throws \Illuminate\Validation\ValidationException
 */
protected function sendLockoutResponse(Request $request)
{
    $seconds = $this->limiter()->availableIn(
        $this->throttleKey($request)
    );

    throw ValidationException::withMessages([
        $this->username() => [trans('auth.throttle', [
            'seconds' => $seconds,
            'minutes' => ceil($seconds / 60),
            'hours' => ceil($seconds / 60 / 60),
        ])],
    ])->status(Response::HTTP_TOO_MANY_REQUESTS);
}

现在您可以像下面这样添加小时节流阀:

'throttle' => 'Too many login attempts. Please try again in :hours hour(s).',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM