*/ protected $fillable = [ 'tenant_id', 'user_id', 'type', 'category', 'amount', 'payment_method', 'description', 'transaction_date', 'reference_number', 'subscription_id', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'amount' => 'decimal:2', 'transaction_date' => 'date', ]; /** * Get the club that owns the transaction. */ public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } /** * Get the user associated with the transaction. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Get the subscription associated with the transaction. */ public function subscription(): BelongsTo { return $this->belongsTo(ClubMemberSubscription::class, 'subscription_id'); } /** * Scope a query to only include income transactions. */ public function scopeIncome($query) { return $query->where('type', 'income'); } /** * Scope a query to only include expense transactions. */ public function scopeExpense($query) { return $query->where('type', 'expense'); } /** * Scope a query to only include refund transactions. */ public function scopeRefund($query) { return $query->where('type', 'refund'); } }