From b4ebd0651a1accadf8a4485f174783f899381782 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Tue, 10 Dec 2024 22:43:56 +0700 Subject: [PATCH] #28 fix: analyse --- src/Providers/RouteServiceProvider.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 8c6cfd6..b8de82b 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -2,6 +2,7 @@ namespace CSlant\Blog\ApiPackage\Providers; +use CSlant\Blog\Core\Models\User; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Http\Request; @@ -21,7 +22,11 @@ public function boot(): void protected function configureRateLimiting(): void { RateLimiter::for((string) config('blog-api.defaults.route_prefix'), function (Request $request) { - return Limit::perMinute(40)->by(optional($request->user())->id ?: $request->ip()); + /** @var User|null $user */ + $user = $request->user(); + $identifier = $user ? $user->id : $request->ip(); + + return Limit::perMinute(40)->by($identifier); }); } }