# Tag Model
DB Table Name | {wp_db_prefix}_fc_tags |
---|---|
Schema | Check Schema |
Source File | fluent-crm/app/Models/Tag.php |
Name Space | FluentCrm\App\Models |
Class | FluentCrm\App\Models\Tag |
# Attributes
Attribute | Data Type | Comment |
---|---|---|
id | Integer | |
title | String | |
slug | String | |
description | String | |
created_at | Date Time | |
updated_at | Date Time |
# Usage
Please check Model Basic for Common methods.
# Accessing Attributes
$tag = FluentCrm\App\Models\Tag::find(1);
$tag->id; // returns id
$tag->title; // returns tag title
.......
1
2
3
4
5
6
2
3
4
5
6
# Fillable Attributes
'title',
'slug',
'description'
1
2
3
4
2
3
4
# Scopes
This model has the following scopes that you can use
# searchBy()
Apply full text search to basic data attributes
title
,slug
, description
- Parameters
- $search - String
# Usage:
// Search all contacts to match "My-Tag"
$tags = FluentCrm\App\Models\Tag::searchBy('"My-Tag')->get();
1
2
2
# Relations
This model has the following relationships that you can use
# subscribers
Access all the associated subscribers of a model
- return
FluentCrm\App\Models\Subscriber
Model Collections
# Example:
// Accessing Subscribers
$subscribers = $tag->subscribers;
// For Filtering by subscribers relationship
// Get tags which has subscriber ids: 1/2/3
$tags = FluentCrm\App\Models\Tag::whereHas('subscribers', function($query) {
$query->whereIn('id', [1,2,3]);
})->get();
// Get tags which does not have subscriber ids: 1/2/3
$tags = FluentCrm\App\Models\Tag::whereDoesntHave('subscribers', function($query) {
$query->whereIn('id', [1,2,3]);
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.
# totalCount()
Get total number of subscribers of a tag
- Parameters
- none
- Returns
int
# Usage
$total = $tag->totalCount();
1
# countByStatus($status)
Get total number of subscribers of a tag where subscriber status is $status
- Parameters
- $status
string
default valuesubscribed
- $status
- Returns
int
# Usage
$total = $tag->countByStatus('subscribed');
1