Skip to content
View as Markdown

Subscriber Pivot Model

DB Table Name{wp_db_prefix}_fc_subscriber_pivot
SchemaCheck Schema
Source Filefluent-crm/app/Models/SubscriberPivot.php
Name SpaceFluentCrm\App\Models
ClassFluentCrm\App\Models\SubscriberPivot

Shared Pivot Table

This table is used for Tags, Lists, and Companies relationships. The object_type column stores the fully-qualified class name to discriminate between them:

  • FluentCrm\App\Models\Tag
  • FluentCrm\App\Models\Lists
  • FluentCrm\App\Models\Company

Attributes

AttributeData TypeComment
idInteger
subscriber_idIntegerFK to fc_subscribers.id
object_idIntegerFK to tag/list/company ID
object_typeStringFully-qualified class name (discriminator)
statusString
is_publicBoolean
created_atDate Time
updated_atDate Time

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php

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

$pivot->id; // returns id
$pivot->object_type; // returns the class name
.......

Scopes

filter($constraints)

Filter by any attribute (subscriber_id, object_id, object_type, status, is_public)

  • Parameters
    • $constraints array

Usage:

php
$pivots = FluentCrm\App\Models\SubscriberPivot::filter([
  'subscriber_id' => 1,
  'object_type'   => 'FluentCrm\App\Models\Tag'
])->get();

Methods

store($attributes) static

Create a new pivot record with auto timestamps

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

Usage

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

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

Attach tags/lists/companies to a subscriber. Creates pivot rows using firstOrCreate and fires appropriate hooks.

  • Parameters
    • $items array — Tag, List, or Company IDs
    • $subscriber int — Subscriber ID
    • $type string — Fully-qualified class name
  • Returns void

Usage

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

detach($items, $subscriber, $type) static

Detach tags/lists/companies from a subscriber. Deletes pivot rows and fires appropriate hooks.

  • Parameters
    • $items array — Tag, List, or Company IDs
    • $subscriber int — Subscriber ID
    • $type string — Fully-qualified class name
  • Returns void

Usage

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