簡體   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