您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Laravel的throttle中间件失效问题解决方法

2024/6/8 20:52:25发布24次查看
本文实例讲述了laravel的throttle中间件失效问题解决方法。分享给大家供大家参考,具体如下:
按官方解释,实现访问频率限制非常简单:
route::get('test', function(){ return 'helle world' ; })->middleware('throttle');
也确实如此,cache存储访问次数,做出判断。
之前使用了zizaco/entrust(一个基于角色的权限管理包),其中把 .env 中的cache_driver=file 改为了 cache_driver=array。所以问题出现了。laravel支持多种cache驱动,file, array, db, redis等,但是throttle 好像使用file类型的驱动才有效。
我的修改如下:
vendor/illuminate/cache/ratelimiter.php 文件
public function __construct(cache $cache) { $this->cache = $cache; } public function __construct() { $this->cache = app('cache')->driver('file'); }
把上面的改为下面的就可以了。throttle中间件也起作用了。
更多laravel的throttle中间件失效问题解决方法。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product