所以,一个简单的方法就是改变油门中间件。
首先,创建它扩展了基本节气门中间件这样一个新的中间件:
namespace App\Http\Middleware;
use Illuminate\Routing\Middleware\ThrottleRequests as
BaseThrottleRequests;
class ThrottleRequests extends BaseThrottleRequests
{
}
然后更改应用程序的油门中间件/ HTTP/Kernel.php:
'throttle' => \App\Http\Middleware\ThrottleRequests::class
它将现在使用自己的油门中间件,并且从laravel延伸出来,它具有它的功能并且像以前一样工作。
然后,查看基类内部的内容,您会发现buildResponse
会在出现Attemps过多的情况下构建响应。因此,你只需要重写它的中间件里面:
protected function buildResponse($key, $maxAttempts)
{
$retryAfter = $this->limiter->availableIn($key); // This gives you the number of seconds before the next time it is available
return redirect('test')->with('error', '...'); // You can use redirect() and all those stuffs as you would normally do to redirect the user and set a session message
}
谢谢你洙多亚历克斯,它就像一个魅力:) – user2983865
不客气:) –
亚历克斯,我有一个问题。你的解决方案效果很好,但我显示错误消息硬编码像这样:'返回重定向('测试') - >与('错误','尝试10分钟后');'有可能显示重试 - 后动态?我的意思是,如果5分钟左显示'尝试5分钟后'等。 – user2983865