'integer', 'amount' => 'decimal:2', // adjust precision if needed 'transaction_fee' => 'decimal:2', // adjust precision if needed 'transaction_date' => 'datetime', 'is_full_payment' => 'boolean', ]; /* Optional relationship */ public function payment() { return $this->belongsTo(Payment::class, 'payment_id'); } /* ========================= * CI method equivalents * ========================= */ public static function getTransactionsByPaymentId(int $paymentId): array { return static::query() ->where('payment_id', $paymentId) ->orderByDesc('transaction_date') ->get() ->toArray(); } public static function getTransactionById(string $transactionId): ?self { return static::query() ->where('transaction_id', $transactionId) ->first(); } /** * Update payment_status by transaction_id (not PK). */ public static function updateTransactionStatus(string $transactionId, string $status): bool { return static::query() ->where('transaction_id', $transactionId) ->update(['payment_status' => $status]) >= 0; } public static function getTotalPaidByPaymentId(int $paymentId): float { $sum = static::query() ->where('payment_id', $paymentId) ->sum('amount'); return (float) $sum; } public static function updateTransactionFee(string $transactionId, float $transactionFee): bool { return static::query() ->where('transaction_id', $transactionId) ->update(['transaction_fee' => $transactionFee]) >= 0; } public static function getLatestTransactionByPaymentId(int $paymentId): ?self { return static::query() ->where('payment_id', $paymentId) ->orderByDesc('transaction_date') ->first(); } }