Skip to content

Referral

Represents a commission event generated when a referred visitor completes a qualifying action.

Table: fa_referrals
Class: FluentAffiliate\\App\\Models\\Referral.php

Columns

ColumnTypeNullableDefaultDescription
idBIGINT(20)NOPrimary key, auto-increment.
affiliate_idBIGINT(20)YESAffiliate who earned this referral.
parent_idBIGINT(20)YESParent referral ID (for multi-tier, reserved).
customer_idBIGINT(20)YESCustomer record associated with this purchase.
visit_idBIGINT(20)YESVisit that initiated this referral (if known).
descriptionLONGTEXTYESFree-text description.
statusVARCHAR(100)YESpendingRecord status.
amountDOUBLEYESNULLCommission amount earned by the affiliate.
order_totalDOUBLEYESNULLTotal order value that generated the referral.
currencyCHAR(3)YESISO 4217 currency code (e.g. USD).
utm_campaignVARCHAR(100)YESUTM campaign parameter from the tracking URL.
providerVARCHAR(100)YESIntegration slug that created this referral (e.g. woo, fluentcart).
provider_idBIGINT(20)YESProvider-specific order/payment numeric ID.
provider_sub_idVARCHAR(192)YESProvider-specific sub-ID (e.g. subscription ID).
productsLONGTEXTYESJSON list of product IDs in the order.
payout_transaction_idBIGINT(20)YESPayout transaction that included this referral.
payout_idBIGINT(20)YESParent payout record.
typeVARCHAR(100)YESsaleCreative type — image, text, html, banner.
settingsLONGTEXTYESSerialized JSON settings blob.
created_atTIMESTAMPYESTimestamp when the record was created.
updated_atTIMESTAMPYESTimestamp when the record was last updated.

Relationships

MethodTypeTargetDescription
affiliate()belongsToAffiliateAffiliate who earned this referral.
customer()belongsToCustomerCustomer who made the purchase.
visit()belongsToVisitClick-through visit that led to this referral.
payout()belongsToPayoutPayout batch that paid this referral.
transaction()belongsToTransactionPayout transaction record.

Query Scopes

ScopeDescription
ofStatus($status)Filter by status.
searchBy($search)Search across description and provider fields.
filterByAffiliate($id)Restrict to a specific affiliate.

Usage Example

php
use FluentAffiliate\App\Models\Referral;

$unpaid = Referral::ofStatus('unpaid')
    ->where('affiliate_id', $affiliateId)
    ->sum('amount');

Released under the GPL-2.0 License.