hay*_*ran 5 throttling laravel
我正在使用 ThrottleRequest 来限制登录尝试。在 Kendler.php 我有
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
Run Code Online (Sandbox Code Playgroud)
和我在 web.php 中的路线
Route::post('login', ['middleware' => 'throttle:3,1', 'uses' => 'Auth\LoginController@authenticate']);
Run Code Online (Sandbox Code Playgroud)
当我第四次登录时,它返回状态 429 并带有消息“TOO MANY REQUESTS”。(默认情况下,我猜)
但我只想返回错误消息,例如:
return redirect('/login')
->withErrors(['errors' => 'xxxxxxx']);
Run Code Online (Sandbox Code Playgroud)
谁来帮帮我!谢谢你!
您可以扩展中间件并覆盖该buildException()方法以更改它在抛出 a 时传递的消息,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);
}
Run Code Online (Sandbox Code Playgroud)