Define a named limiter and attach it to the API route group: ```php use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Support\Facades\RateLimiter; RateLimiter::for('api', function ($request) { return Limit::perMinute(60)->by( $request->user()?->id ?: $request->ip() ); }); ``` ```php Route::prefix('v1') ->middleware(['throttle:api', 'auth:sanctum']) ->group(function () { Route::get('/posts', [PostController::class, 'index']); }); ``` Key authenticated users by user ID and anonymous calle...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Laravel Api?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-laravel-api-c4ab16be)
Define a named limiter and attach it to the API route group:
```php
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('api', function ($request) {
return Limit::perMinute(60)->by(
$request->user()?->id ?: $request->ip()
);
});
```
```php
Route::prefix('v1')
->middleware(['throttle:api', 'auth:sanctum'])
->group(function () {
Route::get('/posts', [PostController::class, 'index']);
});
```
Key authenticated users by user ID and anonymous callers by IP so one user cannot consume a shared global bucket. Tune the limit by endpoint sensitivity and return Laravel's normal `429 Too Many Requests` response, including retry information where appropriate. Keep the limiter definition in the application service-provider bootstrap path and verify both authenticated and anonymous behavior with feature tests.