Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

abrudtkuhl/laracloudpricing

19 stars
2 code files
View abrudtkuhl/laracloudpricing on GitHub

app/Services/PricingService.php

Open in GitHub
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
 
class PricingService
{
protected $config;
protected $region = 'us-ohio';
protected $apiKey;
 
public function __construct()
{
$this->config = Config::get('laracloud');
$this->apiKey = env('OPENAI_API_KEY');
}
 
// ...
 
public function getPostgresMinCpu(): float
{
return Arr::get($this->config, "database.{$this->region}.postgres.min_cpu", 0.25);
}
 
public function getMySqlDefaultSizeKey(): ?string
{
$sizes = $this->getAvailableMySqlSizes();
return !empty($sizes) ? array_key_first($sizes) : null;
}
 
public function getKvDefaultTierKey(): ?string
{
$tiers = $this->getAvailableKvTiers();
return !empty($tiers) ? array_key_first($tiers) : null;
}
 
public function getComputeDefaultSizeKey(): ?string
{
$sizes = Arr::get($this->config, "compute.{$this->region}", []);
return !empty($sizes) ? array_key_first($sizes) : null;
}
 
// ...
}

app/Livewire/PricingCalculator.php

Open in GitHub
use App\Services\PricingService;
use Livewire\Component;
use Livewire\Attributes\Title;
use Livewire\Attributes\Computed;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Validator;
use Livewire\Attributes\On;
 
class PricingCalculator extends Component
{
protected PricingService $pricingService;
 
// ...
 
public string $webComputeSize;
public string $workerComputeSize;
public ?string $mysqlDatabaseSize;
public float $postgresComputeUnits;
public string $kvTier;
 
// ...
 
public function boot(PricingService $pricingService)
{
$this->pricingService = $pricingService;
}
 
public function mount()
{
// Initialize properties using the service
$this->webComputeSize = $this->pricingService->getComputeDefaultSizeKey();
$this->workerComputeSize = $this->pricingService->getComputeDefaultSizeKey();
$this->mysqlDatabaseSize = $this->pricingService->getMySqlDefaultSizeKey();
$this->postgresComputeUnits = $this->pricingService->getPostgresMinCpu();
$this->kvTier = $this->pricingService->getKvDefaultTierKey();
 
$this->resetUsageToPlanDefaults();
}
 
// ...
 
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.