1. Go to this page and download the library: Download zaber-dev/laravel-quota 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/ */
// Immediately reset the quota counter for the current period window
Quota::for('api_queries', $user)->reset();
// Flush all historical quota records for this action and target
Quota::for('api_queries', $user)->flush();
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ZaberDev\Quota\HasQuotas;
class User extends Authenticatable
{
use HasQuotas;
}
$user = User::find(1);
// Consume 1 PDF export quota from the user's monthly budget
$user->quota('pdf_exports')->limit(25)->perMonth()->consume();
// Check remaining budget
$remaining = $user->quota('pdf_exports')->limit(25)->perMonth()->remaining();
// Get all database quota records assigned to this user
$activeQuotas = $user->quotas()->where('period_end', '>', now())->get();
// Delete all quota records for this user
$user->quotas()->delete();
use Illuminate\Support\Facades\Route;
// Enforce a monthly allowance of 50 exports per User / IP address
Route::post('/exports/generate', [ExportController::class, 'store'])
->middleware('quota:exports,50,month');
// Use a specific storage backend
Route::post('/api/v1/query', [ApiController::class, 'query'])
->middleware('quota:api_query,1000,day,database');
// Store high-frequency API checks in fast cache/Redis
Quota::for('api_ping', $ip)->using('cache')->limit(5000)->perDay()->consume();
// Store critical billing tier budgets in SQL database
Quota::for('monthly_exports', $user)->using('database')->limit(50)->perMonth()->consume();
use ZaberDev\Quota\Contracts\QuotaDriverContract;
use ZaberDev\Quota\Facades\Quota;
public function boot(): void
{
Quota::extend('dynamodb', function ($app) {
return new MyDynamoDbQuotaDriver($app['config']['quotas.drivers.dynamodb']);
});
}
use Illuminate\Support\Facades\Schedule;
use ZaberDev\Quota\Models\Quota;
Schedule::command('model:prune', ['--model' => Quota::class])->daily();