HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/app/Model/SubscriptionCreditState.php
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * subscription_credit_state — cold-path snapshot of credits per subscription.
 *
 * Hot-path (CreditsService::canUse/consume) uses CreditTracker (file-based). This
 * table is the eventually-consistent durable view for admin UI, API, and audit.
 * Synced from tracker by CreditStateSyncJob.
 *
 * See docs/payment-order-plan-subscription-saas/SUBSCRIPTION-COMPREHENSIVE-DESIGN.md §3.2.
 */
class SubscriptionCreditState extends Model
{
    use HasFactory;

    protected $connection = 'mysql';
    protected $table = 'subscription_credit_state';

    protected $fillable = [
        'subscription_id',
        'credit_key',
        'remaining',
        'granted_per_cycle',
        'reset_at',
        'last_synced_at',
    ];

    protected $casts = [
        'remaining'         => 'integer',
        'granted_per_cycle' => 'integer',
        'reset_at'          => 'datetime',
        'last_synced_at'    => 'datetime',
    ];

    public function subscription()
    {
        return $this->belongsTo(Subscription::class);
    }

    protected static function newFactory()
    {
        return \Database\Factories\SubscriptionCreditStateFactory::new();
    }
}