# Template Model

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

# Attributes

Attribute Data Type Comment
ID Integer
post_author Integer
post_date Date Time
post_date_gmt Date Time
post_content Long Text
post_title Text
post_excerpt Text
post_status String
comment_status String
ping_status String
post_name String
post_type String
post_mime_type String
post_date Date Time
post_modified Date Time

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$template = FluentCrm\App\Models\Template::find(1);

$template->id; // returns id
$template->post_status; // returns post status
.......
1
2
3
4
5
6

# Fillable Attributes

'ID',
'post_author',
'post_date',
'post_date_gmt',
'post_content',
'post_title',
'post_excerpt',
'post_status',
'comment_status',
'ping_status',
'post_name',
'post_type',
'post_mime_type',
'post_date',
'post_modified'

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

# Scopes

This model has the following scope that you can use

# emailTemplates($types)

returns all email templates by filtering post_status

  • Parameters
    • $types - array - default ['publish']

# Usage:

$emailTemplates = FluentCrm\App\Models\Template::emailTemplates(['draft', 'publish'])->get();
1

# campaignTemplate()

returns all email templates by filtering post_status

  • Parameters
    • none

# Usage:

$campaignTemplate = FluentCrm\App\Models\Template::campaignTemplate()->get();
1

# Relations

This model has the following relationships that you can use

# campaign

Get the campaign of model

  • returns FluentCrm\App\Models\Campaign Model

# Example:

// Accessing actions
$campaign = $funnel->campaign;
1
2

// You can also limit your results based on the existence of a relationship. For example, if you want to get all the templates that have ids 1, 2 and 3 in the campaign, you can do the following:

// Get Templates which have campaign ids: 1/2
$templates = FluentCrm\App\Models\Template::whereHas('campaign', function($query) {
    $query->whereIn('id', [1,2]);
})->get();
1
2
3
4

# Methods

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

# render($content)

Render the template content

  • Parameters
    • $content string Default: null
  • Returns string

# Usage

$renderedText = $template->render();
1