gpt4 book ai didi

Laravel throttle 消息

转载 作者:行者123 更新时间:2023-12-03 16:14:18 25 4
gpt4 key购买 nike

我正在使用 ThrottleRequest 来限制登录尝试。
在 Kendler.php 我有

'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

和我在 web.php 中的路线
Route::post('login', ['middleware' => 'throttle:3,1', 'uses' => 'Auth\LoginController@authenticate']);

当我第四次登录时,它返回状态 429 并带有消息“TOO MANY REQUESTS”。
(默认我猜)
但我只想返回错误消息,例如:
return redirect('/login')
->withErrors(['errors' => 'xxxxxxx']);

谁来帮帮我!谢谢你!

最佳答案

您可以扩展中间件并覆盖 buildException()方法在抛出 ThrottleRequestsException 时更改它传递的消息或者您可以使用您的异常处理程序来捕获 ThrottleRequestsException做任何你想做的事。

所以在 Exceptions/Handler.php你可以做类似的事情

use Illuminate\Http\Exceptions\ThrottleRequestsException;

public function render($request, Exception $exception)
{
if ($exception instanceof ThrottleRequestsException) {
//Do whatever you want here.
}

return parent::render($request, $exception);
}

关于Laravel throttle 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52755102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com