# 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 |
::: tip 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
| Attribute |
Data Type |
Comment |
| id |
Integer |
|
| subscriber_id |
Integer |
FK to fc_subscribers.id |
| object_id |
Integer |
FK to tag/list/company ID |
| object_type |
String |
Fully-qualified class name (discriminator) |
| status |
String |
|
| is_public |
Boolean |
|
| created_at |
Date Time |
|
| updated_at |
Date 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)
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)
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)
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');
```