danharrin/livewire-rate-limiting
Add rate limiting to Laravel Livewire actions with a simple trait/middleware-style API. Throttle clicks, form submits, and other events to prevent spam and brute force attempts. Configure limits, decay, and messages per component or action.
RateLimiter facade, but now benefits from Laravel 13’s improved service container and configuration system (e.g., app()->bind() for resolvers).Illuminate\Support\Traits\Macroable updates) are likely handled internally by the package.RateLimited) and helpers (e.g., withRateLimiting()) should work as before.assertSeeInOrder) can now be used to validate rate-limit responses, but no package-specific test utilities are introduced.Http\Client, ensure no conflicts with Livewire’s underlying HTTP layer (unlikely, but worth auditing).config:cache improvements may require clearing cached configs post-upgrade (php artisan config:clear).RateLimiter::for() syntax) to extend the package’s functionality?bootstrap/app.php changes)?Cache::tags()) can enhance key management.composer show laravel/framework). If not, upgrade first:
composer require laravel/framework:^13.0
composer require danharrin/livewire-rate-limiting:^2.2.0
php artisan config:clear
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
class MyComponent extends Component
{
use WithRateLimiting;
public function submitForm()
{
return withRateLimiting('submit-form', fn () => [
'maxAttempts' => 5,
'decaySeconds' => 10,
]);
}
}
spatie/laravel-activitylog if using custom rate-limit keys).composer.json and run composer update.php artisan config:clear
php artisan view:clear
config/ system to centralize rate-limit rules (e.g., using config/rate-limiting.php with environment-specific overrides).telescope:install for rate-limit event tracking.RateLimiter::tooManyAttempts(function () {
Log::channel('rate_limits')->warning('Exceeded', ['key' => $key]);
});
trans() with JSON files).RateLimiter::extend('custom', function () {
return Limit::perMinute(5)->response(function () {
return response()->json(['error' => trans('rate_limit.exceeded')], 429);
});
});
Illuminate\Queue\AsyncQueue).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Laravel 13.x upgrade issues | Broken Livewire actions | Roll back to Laravel 12.x temporarily; test in staging first. |
| Redis cache saturation | Rate-limiting disabled | Implement circuit breakers (e.g., fallback to database tracking). |
| Livewire action race conditions | False rate-limit triggers | Use wire:ignore.self or client-side throttling (e.g., Alpine.js debounce). |
| Package version conflicts | Dependency resolution failures | Pin the package version in composer.json and test upgrades incrementally. |
bootstrap/app.php changes).RateLimiter::for()).app()->bind():
$this->app->bind(RateLimitResolver::class, function () {
return new CustomRateLimitResolver();
});
How can I help you explore Laravel packages today?