Skip to content
View as Markdown

Template Model

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

Attributes

AttributeData TypeComment
IDInteger
post_authorInteger
post_dateDate Time
post_date_gmtDate Time
post_contentLong Text
post_titleText
post_excerptText
post_statusString
comment_statusString
ping_statusString
post_nameString
post_typeString
post_mime_typeString
post_dateDate Time
post_modifiedDate Time

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php

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

$template->id; // returns id
$template->post_status; // returns post status
.......

Fillable Attributes

php
'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'

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:

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

campaignTemplate()

returns all email templates by filtering post_status

  • Parameters
    • none

Usage:

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

Relations

This model has the following relationships that you can use

campaign

Get the campaign of model

  • returns FluentCrm\App\Models\Campaign Model

Example:

php
// Accessing actions
$campaign = $funnel->campaign;

// 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:

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

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

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