# Subscriber Model

DB Table Name {wp_db_prefix}_fc_subscribers
Schema Check Schema
Source File fluent-crm/app/Models/Subscriber.php
Name Space FluentCrm\App\Models
Class FluentCrm\App\Models\Subscriber

# Attributes

Attribute Data Type Comment
id Integer
user_id Integer
hash String
contact_owner Integer
company_id Integer
prefix String
first_name String
last_name String
email String
timezone String
address_line_1 String
address_line_2 String
postal_code String
city String
state String
country String
ip String
latitude Decimal
longitude Decimal
total_points Integer
life_time_value Integer
phone String
status String
contact_type String
source String
avatar String / URL
date_of_birth Date
created_at Date Time
last_activity Date Time
updated_at Date Time
full_name String concat of first_name and last_name
photo String / URL avatar image url

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$subscriber = FluentCrm\App\Models\Subscriber::find(1);

$subsctiber->id; // returns id
$subscriber->email; // returns email
.......
1
2
3
4
5
6

# Fillable Attributes


'hash',
'prefix',
'first_name',
'last_name',
'user_id',
'email',
'status', // pending | subscribed | bounced | unsubscribed; Default: subscriber
'contact_type', // lead | customer
'address_line_1',
'address_line_2',
'postal_code',
'city',
'state',
'country',
'phone',
'timezone',
'date_of_birth',
'source',
'life_time_value',
'last_activity',
'total_points',
'latitude',
'longitude',
'ip',
'created_at',
'updated_at',
'avatar'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# Scopes

This model has the following scopes that you can use

# searchBy()

Apply full text search to basic data attributes email,first_name, last_name, address_line_1, address_line_2, postal_code, city, state, country, phone,status

  • Parameters
    • $search - String
    • $custom_fields - Boolean, Default false. If true then it will search in Custom Field Too

# Usage:

// Search all contacts to match "John"
$subscribers = FluentCrm\App\Models\Subscriber::searchBy('John')->get();
1
2

# filterByStatues()

Filter contacts by statuses

  • Parameters
    • $statuses - array

# Usage:

// Get all which has pending and unsubscribed statuses
$subscribers = FluentCrm\App\Models\Subscriber::filterByStatues(['pending', 'unsubscribed'])->get();
1
2

# filterByTags()

Filter contacts by tag attributes

  • Parameters
    • $keys - array, Ex: [tag1, tag2, tag3]
    • $filterBy - string, default: 'id' possible value: id / slug / title

# Usage:

// Get all contacts are in 1 / 2 /3 tag ids
$subscribers = FluentCrm\App\Models\Subscriber::filterByTags([1,2,3])->get();
1
2

# filterByNotInTags()

Filter contacts by not in given tags

  • Parameters
    • $keys - array, Ex: [tag1, tag2, tag3]
    • $filterBy - string, default: 'id' possible value: id / slug / title

# Usage:

// Get all contacts who are not in 1 / 2 /3 tag ids
$subscribers = FluentCrm\App\Models\Subscriber::filterByNotInTags([1,2,3])->get();
1
2

# filterByLists()

Filter contacts by tag attributes

  • Parameters
    • $keys - array, Ex: [list1, list2, list3]
    • $filterBy - string, default: 'id' possible value: id / slug / title

# Usage:

// Get all contacts are in 1 / 2 /3 list ids
$subscribers = FluentCrm\App\Models\Subscriber::filterByLists([1,2,3])->get();
1
2

# filterByNotInLists()

Filter contacts by not in given lists

  • Parameters
    • $keys - array, Ex: [list1, list2, list3]
    • $filterBy - string, default: 'id' possible value: id / slug / title

# Usage:

// Get all contacts who are not in 1 / 2 /3 list ids
$subscribers = FluentCrm\App\Models\Subscriber::filterByNotInLists([1,2,3])->get();
1
2

# Relations

This model has the following relationships that you can use

# tags

Access all the associated tag of a model

  • return FluentCrm\App\Models\Tag Model Collections

# Example:

// Accessing Tags
$subscriberTags = $subscriber->tags;

// For Filtering by tags relationship

// Get Subscribers which has tag ids: 1/2/3
$subscribers = FluentCrm\App\Models\Subscriber::whereHas('tags', function($query) {
    $query->whereIn('id', [1,2,3]);
})->get();

// Get Subscribers which does not have tag ids: 1/2/3
$subscribers = FluentCrm\App\Models\Subscriber::whereDoesntHave('tags', function($query) {
    $query->whereIn('id', [1,2,3]);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# lists

Access all the associated lists of a model

  • return FluentCrm\App\Models\List Model Collections

# Example:

// Accessing Lists
$subscriberLists = $subscriber->lists;

// For Filtering by tags relationship

// Get Subscribers which has list ids: 1/2/3
$subscribers = FluentCrm\App\Models\Subscriber::whereHas('lists', function($query) {
    $query->whereIn('id', [1,2,3]);
})->get();

// Get Subscribers which does not have list ids: 1/2/3
$subscribers = FluentCrm\App\Models\Subscriber::whereDoesntHave('lists', function($query) {
    $query->whereIn('id', [1,2,3]);
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# sequences

Access all the associated email sequences of a model

  • return FluentCrm\App\Models\Sequence Model Collections

# Example:

// Accessing All the email sequences of subscriber
$subscriberEmailSequences = $subscriber->sequences;
1
2

# sequence_trackers

Access all the associated email sequence trackers of a Subscriber model

  • return FluentCrm\App\Models\SequenceTracker Model Collections

# Example:

// Accessing All the email sequence trackers of subscriber
$subscriberEmailSequenceTrackers = $subscriber->sequence_trackers;
1
2

# funnels

Access all the associated Automation Funnels of a Subscriber model

  • return FluentCrm\App\Models\Funnel Model Collections

# Example:

// Accessing All the automation funnels of subscriber
$subscriberAutomations = $subscriber->funnels;
1
2

# funnel_subscribers

Access all the associated Automation Funnels Subscription Trackers of a Subscriber model

  • return FluentCrm\App\Models\FunnelSubscriber Model Collections

# Example:

// Accessing All the automation funnel tracking of subscriber
$subscriberAutomationTrackers = $subscriber->funnel_subscribers;
1
2

# campaignEmails

Access all the sent/sending emails of a Subscriber model

  • return FluentCrm\App\Models\CampaignEmail Model Collections

# Example:

// Accessing All the automation funnel tracking of subscriber
$subscriberEmailCollections = $subscriber->campaignEmails;
1
2

# Methods

Along with Global Model methods, this model has few helper methods.

# custom_fields()

Get custom fields data of a contact

  • Parameters
    • none
  • Returns Array

# Usage

$customData = $subscriber->custom_fields();
1

# stats

Get Contact's sent emails, opens and clicks count

  • Parameters
    • none
  • Returns Array

# Usage

$contactStats = $subscriber->stats();
1

# sendDoubleOptinEmail()

Send Double Optin email if contact is in pending status

  • Parameters
    • none
  • Returns boolean

# Usage

$subscriber->sendDoubleOptinEmail();
1

# unsubscribeReason()

Get Unsubscribe reason if contact unsubscribe and provide feedback

  • Parameters
    • none
  • Returns string

# Usage

$reason = $subscriber->unsubscribeReason();
1

# unsubscribeReasonDate()

Get Unsubscribe reason date if contact is unsubscribed

  • Parameters
    • none
  • Returns date string or empty

# Usage

$sunsubscribeDate = $subscriber->unsubscribeReasonDate();
1

# hasAnyTagId()

Check if a contact is any of the provided tag

  • Parameters
    • $tagIds array of tag ids
  • Returns boolean

# Usage

$isInTags = $subscriber->hasAnyTagId([1,2,3]);
1

# hasAnyListId()

Check if a contact is any of the provided list

  • Parameters
    • $listIds array of list ids
  • Returns boolean

# Usage

$isInLists = $subscriber->hasAnyListId([1,2,3]);
1

# getWpUser()

Get WP User object if WordPress user exist of that contact

  • Parameters
    • none
  • Returns \WP_User or null

# Usage

$user = $subscriber->getWpUser();
1

# getWpUserId()

Get WP User object if WordPress user exist of that contact

  • Parameters
    • none
  • Returns INT or null

# Usage

$userId = $subscriber->getWpUserId();
1

# attachLists($listIds)

Attach Lists to a Subscriber

  • Parameters
    • $listIds array
  • Returns FluentCrm\App\Models\Subscriber

# Usage

$subscriber->attachLists([1,2,3]);
1

# detachLists($listIds)

Remove Lists from a Subscriber

  • Parameters
    • $listIds array
  • Returns FluentCrm\App\Models\Subscriber

# Usage

$subscriber->detachLists([1,2,3]);
1

# attachTags($tagIds)

Attach Tags to a Subscriber

  • Parameters
    • $tagIds array
  • Returns FluentCrm\App\Models\Subscriber

# Usage

$subscriber->attachTags([1,2,3]);
1

# detachTags($tagIds)

Remove tags from a Subscriber

  • Parameters
    • $tagIds array
  • Returns FluentCrm\App\Models\Subscriber

# Usage

$subscriber->detachTags([1,2,3]);
1