# Subscriber Pivot Model

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

# Attributes

Attribute Data Type Comment
id Integer
subscriber_id Integer
object_id Integer
object_type String
status String
is_public Boolean
created_at Date Time
updated_at Date Time

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$pivot = FluentCrm\App\Models\SubscriberPivot::find(1);

$pivot->id; // returns id
$pivot->is_public; // returns meta is_public
.......
1
2
3
4
5
6

# Fillable Attributes


'subscriber_id',
'object_id',
'object_type',
'status',
'is_public'
1
2
3
4
5
6

# Scopes

This model has the following scopes that you can use

# filter($constraints)

Filter by subscriber_id, object_id, object_type, status, is_public

  • Parameters
    • $constraints array

# Usage:

// Search all pivots
$pivots = FluentCrm\App\Models\SubscriberPivot::filter([
  'subscriber_id' => 1,
  'object_id'     => 1
])->get();
1
2
3
4
5

# Relations

This model has the following relationships that you can use

# subscriber

Access all the associated subscriber of a model

  • return FluentCrm\App\Models\Subscriber Model Collections

# Example:

// Accessing Subscriber
$subscriber = $note->subscriber;

// For Filtering by subscriber relationship

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

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

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

# Methods

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

# store($attributes)

Store subscriber pivot info

  • Parameters
    • $attributes array
  • Returns FluentCrm\App\Models\SubscriberPivot

# Usage

$pivot = FluentCrm\App\Models\SubscriberPivot::store([
  'subscriber_id' => 1,
  'object_id'     => 1,
  'object_type'   => 'FluentCrm\App\Models\Tag',
  'is_public'     => 1
]);
1
2
3
4
5
6

# attach($items, $subscriber, $type)

Attach tags/lists to the subscriber

  • Parameters
    • $items array List or Tag ids
    • $subscriber int Subscriber ID
    • $type string List or Tag class namespace
  • Returns void

# Usage

FluentCrm\App\Models\SubscriberPivot::attach([1,3], 1, 'FluentCrm\App\Models\Tag');
1