How to solve the problem of Laravel's throttle middleware failure

不言
Release: 2023-04-01 06:08:01
Original
1913 people have browsed it

This article mainly introduces the solution to Laravel's throttle middleware failure problem. It briefly analyzes the reasons for the throttle middleware failure problem and proposes a solution. It has certain reference value. Friends in need can refer to 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

This 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 a variety of 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.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to solve the problem of PHP mkdir() not having write permission

The above is the detailed content of How to solve the problem of Laravel's throttle middleware failure. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!