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)NOPrimary key, auto-increment.
contact_idBIGINT(20)YESOptional FluentCRM contact ID linked to this affiliate.
user_idBIGINT(20)YESWordPress user ID of the affiliate.
group_idBIGINT(20)YESAffiliate 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)YESCustom URL parameter value used for tracking.
payment_emailVARCHAR(192)YESEmail address used for payout delivery.
statusVARCHAR(100)YESactiveRecord status.
settingsLONGTEXTYESSerialized JSON settings blob.
noteLONGTEXTYESInternal admin notes about the affiliate.
created_atTIMESTAMPYESTimestamp when the record was created.
updated_atTIMESTAMPYESTimestamp 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();

Released under the GPL-2.0 License.