Skip to content
View as Markdown

Company Model

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

Attributes

AttributeData TypeComment
idInteger
hashStringAuto-generated on create
nameString
owner_idIntegerFK to fc_subscribers.id
industryString
typeString
emailString
phoneString
address_line_1String
address_line_2String
postal_codeString
cityString
stateString
countryString
timezoneString
employees_numberInteger
descriptionText
logoString / URL
linkedin_urlString / URL
facebook_urlString / URL
twitter_urlString / URL
websiteString / URL
metaTextSerialized array, auto serialize/unserialize via mutators. Contains custom_values.
date_of_startDate
created_atDate Time
updated_atDate Time

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$company = FluentCrm\App\Models\Company::find(1);

$company->id; // returns id
$company->name; // returns company name
$company->meta; // returns deserialized array (auto via accessor)
$company->meta['custom_values']; // returns custom field values

Fillable Attributes

php
'hash',
'name',
'owner_id',
'industry',
'type',
'email',
'phone',
'address_line_1',
'address_line_2',
'postal_code',
'city',
'state',
'country',
'timezone',
'employees_number',
'description',
'logo',
'linkedin_url',
'facebook_url',
'twitter_url',
'meta',
'website',
'date_of_start',
'created_at',
'updated_at'

Scopes

searchBy()

Search companies by name, phone, description, and email

  • Parameters
    • $search - String

Usage:

php
$companies = FluentCrm\App\Models\Company::searchBy('Acme')->get();

ofType()

Filter companies by type

  • Parameters
    • $status - String

Usage:

php
$companies = FluentCrm\App\Models\Company::ofType('enterprise')->get();

ofIndustry()

Filter companies by industry

  • Parameters
    • $status - String

Usage:

php
$companies = FluentCrm\App\Models\Company::ofIndustry('technology')->get();

Relations

subscribers

Access all associated contacts of a company (via pivot table)

  • return FluentCrm\App\Models\Subscriber Model Collections (BelongsToMany via fc_subscriber_pivot)

Example:

php
// Accessing subscribers
$contacts = $company->subscribers;

// Filter companies by subscriber
$companies = FluentCrm\App\Models\Company::whereHas('subscribers', function($query) {
    $query->where('status', 'subscribed');
})->get();

owner

Access the owner contact of the company

  • return FluentCrm\App\Models\Subscriber Model (BelongsTo via owner_id)

Example:

php
// Accessing owner
$owner = $company->owner;

notes

Access all notes for this company

  • return FluentCrm\App\Models\CompanyNote Model Collections

Shared Table

Notes are stored in the fc_subscriber_notes table with status = '_company_note_'. The subscriber_id column stores the company ID in this context.

Example:

php
// Accessing company notes
$notes = $company->notes;

Methods

getContactsCount()

Get the number of associated contacts

  • Parameters
    • none
  • Returns int

Usage

php
$count = $company->getContactsCount();

getCustomValues()

Get custom field values from the meta attribute

  • Parameters
    • none
  • Returns array

Usage

php
$customValues = $company->getCustomValues();

mappables() static

Get human-readable label map for all importable/mappable field keys

  • Parameters
    • none
  • Returns array

Usage

php
$fieldMap = FluentCrm\App\Models\Company::mappables();