Skip to content

Affiliate ​

Represents a registered affiliate. Central model in FluentAffiliate.

Table: fa_affiliates
Class: FluentAffiliate\\App\\Models\\Affiliate.php

Columns ​

ColumnTypeNullableDefaultDescription
idBIGINT(20)NO—Primary key, auto-increment.
contact_idBIGINT(20)YES—Optional FluentCRM contact ID linked to this affiliate.
user_idBIGINT(20)YES—WordPress user ID of the affiliate.
group_idBIGINT(20)YES—Affiliate group ID (Pro feature).
rateDOUBLEYESNULLCommission rate. Interpretation depends on rate_type.
total_earningsDOUBLEYES0Cumulative lifetime earnings (denormalised).
unpaid_earningsDOUBLEYES0Earnings not yet included in a paid payout.
referralsBIGINT(20)YES0Total referral count (denormalised).
visitsBIGINT(20)YES0Total visit count (denormalised).
lead_countsBIGINT(20)YES0Total lead count (denormalised).
rate_typeVARCHAR(100)YESpercentageCommission type — percentage or flat.
custom_paramVARCHAR(100)YES—Custom URL parameter value used for tracking.
payment_emailVARCHAR(192)YES—Email address used for payout delivery.
statusVARCHAR(100)YESactiveRecord status.
settingsLONGTEXTYES—Serialized JSON settings blob.
custom_fieldsJSONYES—JSON map of custom registration field values, keyed by field key (Pro feature — added by the DB-version migration).
noteLONGTEXTYES—Internal admin notes about the affiliate.
created_atTIMESTAMPYES—Timestamp when the record was created.
updated_atTIMESTAMPYES—Timestamp when the record was last updated.

Relationships ​

MethodTypeTargetDescription
user()belongsToUserWordPress user owning this affiliate account.
referrals()hasManyReferralAll referrals attributed to this affiliate.
visits()hasManyVisitAll tracked visits attributed to this affiliate.
transactions()hasManyTransactionAll payout transactions for this affiliate.
payouts()belongsToManyPayoutPayouts that include this affiliate.
group()belongsToAffiliateGroupAffiliate group (Pro).
meta()hasManyMetaMeta key-value pairs for this affiliate.

Query Scopes ​

ScopeDescription
ofStatus($status)Filter by status.
searchBy($search)Full-text search across user email/name and custom_param.
filterByGroups($ids)Restrict to affiliates in the given group IDs.

Usage Example ​

php
use FluentAffiliate\App\Models\Affiliate;

// Active affiliates with earnings
$affiliates = Affiliate::ofStatus('active')
    ->where('unpaid_earnings', '>', 0)
    ->orderBy('total_earnings', 'desc')
    ->get();

FluentAffiliate developer documentation