Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 989e35b

Browse files
committed
Add API throttling
1 parent 1409514 commit 989e35b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/Providers/AppServiceProvider.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace App\Providers;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Cache\RateLimiting\Limit;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\RateLimiter;
69

710
class AppServiceProvider extends ServiceProvider
811
{
@@ -19,6 +22,8 @@ public function register(): void
1922
*/
2023
public function boot(): void
2124
{
22-
//
25+
RateLimiter::for('api', function (Request $request) {
26+
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
27+
});
2328
}
2429
}

0 commit comments

Comments
 (0)