[英]: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 只給出minutes
和seconds
,如果你想添加小時,只需覆蓋Illuminate\Foundation\Auth\ThrottlesLogins
的sendLockoutResponse
方法,如下所示(在使用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.