PHP code example of abolaradev / livewire-rate-limiter
1. Go to this page and download the library: Download abolaradev/livewire-rate-limiter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abolaradev / livewire-rate-limiter example snippets
return [
/**
* Maximum number of allowed attempts within the decay period.
*/
'maxAttempts' => 10,
/**
* Number of seconds before the attempt counter is reset.
*/
'decaySeconds' => 60,
];
use Abolaradev\LivewireRateLimiter\Attributes\RateLimiter;
use Livewire\Component;
new class extends Component
{
#[RateLimiter()]
public function oneTimePassword()
{
$this->send();
}
};
#[RateLimiter(maxAttempts: 5, decaySeconds: 120)]
public function oneTimePassword()
{
$this->send();
}
use Abolaradev\LivewireRateLimiter\Facades\LivewireRateLimiter;
use Livewire\Component;
new class extends Component
{
public function oneTimePassword()
{
LivewireRateLimiter::handle(
onAction: fn () => $this->send()
);
}
};
public function oneTimePassword()
{
LivewireRateLimiter::handle(
onAction: fn () => $this->send(),
onLimit: fn () => $this->js("alert('Too Many Requests')")
);
}
public int $available;
public function oneTimePassword()
{
LivewireRateLimiter::handle(
onAction: fn () => $this->send(),
onLimit: fn () => $this->available = LivewireRateLimiter::getAvailableIn()
);
}