PHP code example of kbeaud11 / laravel-cloud-tracker
1. Go to this page and download the library: Download kbeaud11/laravel-cloud-tracker 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/ */
// Enterprise client at 75% rate
$org->trackingPolicy()->update(['usage_multiplier' => 0.7500]);
// At-cost client at 100% (default)
$org->trackingPolicy()->update(['usage_multiplier' => 1.0000]);
// Premium support client at 150% markup
$org->trackingPolicy()->update(['usage_multiplier' => 1.5000]);
// All events for an organization
$org->usageEvents()->where('feature', 'merge')->get();
// Monthly rollups
$org->usageRollups()
->where('period_start', '2026-02-01')
->get();
// Total cost this month
$org->usageRollups()
->where('period_start', now()->startOfMonth())
->sum('total_cost');
use LaravelCloudTracker\Models\UsageRollup;
use LaravelCloudTracker\Models\UsageEvent;
// Top 10 most expensive features this month
UsageRollup::where('period_start', now()->startOfMonth())
->orderByDesc('total_cost')
->limit(10)
->get();
// Recent events with cost breakdown
UsageEvent::where('feature', 'segment_rebuild')
->latest()
->limit(50)
->get()
->each(function ($event) {
// $event->cost_dimensions contains per-dimension breakdown:
// [
// 'compute' => ['ms' => 150.23, 'cost' => 0.00000024],
// 'cache' => ['quantity' => 25, 'cost' => 0.000015],
// ]
});
use LaravelCloudTracker\Contracts\TrackingPolicyResolver;
class CustomPolicyResolver implements TrackingPolicyResolver
{
public function shouldTrack(Model $model, string $feature): bool
{
// Your custom logic — check feature flags, plan tiers, etc.
}
public function getMultiplier(Model $model): float
{
// Dynamic pricing based on plan, usage tier, time of day, etc.
}
public function flush(): void
{
// Clear any caches
}
}