Home > php教程 > PHP开发 > Solution to Laravel's throttle middleware failure problem

Solution to Laravel's throttle middleware failure problem

高洛峰
Release: 2016-12-27 11:46:35
Original
1798 people have browsed it

The example in this article describes how to solve the problem of Laravel's throttle middleware failure. Share it with everyone for your reference, the details are as follows:

According to the official explanation, it is very simple to implement access frequency limit:

Route::get('test', function(){
  return 'helle world' ;
})->middleware('throttle');
Copy after login

It is indeed the case, The cache stores the number of accesses and makes judgments.

I used zizaco/entrust (a role-based permission management package) before, in which CACHE_DRIVER=file in .env was changed to CACHE_DRIVER=array. So the problem arises. Laravel supports multiple cache drivers, including File, Array, Db, Redis, etc., but throttle seems to be effective only when using File type drivers.

My modifications are as follows:

vendor/illuminate/cache/RateLimiter.php file

public function __construct(Cache $cache)
{
    $this->cache = $cache;
}
public function __construct()
{
    $this->cache = app('cache')->driver('file');
}
Copy after login

Change the above Just do the following. The throttle middleware also works.

For more articles related to solutions to Laravel’s throttle middleware failure problem, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template