# 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
```php
$tag = FluentCrm\App\Models\Tag::find(1);
$tag->id; // returns id
$tag->title; // returns tag title
.......
```
## Fillable Attributes
```php
'title',
'slug',
'description'
```
## 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:
```php
// Search all contacts to match "My-Tag"
$tags = FluentCrm\App\Models\Tag::searchBy('"My-Tag')->get();
```
## 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:
```php
// 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();
```
## 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
```php
$total = $tag->totalCount();
```
### countByStatus($status)
Get total number of subscribers of a tag where subscriber status is $status
- Parameters
- $status `string` default value `subscribed`
- Returns `int`
#### Usage
```php
$total = $tag->countByStatus('subscribed');
```