Company Model
| DB Table Name | {wp_db_prefix}_fc_companies |
|---|---|
| Schema | Check Schema |
| Source File | fluent-crm/app/Models/Company.php |
| Name Space | FluentCrm\App\Models |
| Class | FluentCrm\App\Models\Company |
Attributes
| Attribute | Data Type | Comment |
|---|---|---|
| id | Integer | |
| hash | String | Auto-generated on create |
| name | String | |
| owner_id | Integer | FK to fc_subscribers.id |
| industry | String | |
| type | String | |
| String | ||
| phone | String | |
| address_line_1 | String | |
| address_line_2 | String | |
| postal_code | String | |
| city | String | |
| state | String | |
| country | String | |
| timezone | String | |
| employees_number | Integer | |
| description | Text | |
| logo | String / URL | |
| linkedin_url | String / URL | |
| facebook_url | String / URL | |
| twitter_url | String / URL | |
| website | String / URL | |
| meta | Text | Serialized array, auto serialize/unserialize via mutators. Contains custom_values. |
| date_of_start | Date | |
| created_at | Date Time | |
| updated_at | Date 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 valuesFillable 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\SubscriberModel Collections (BelongsToMany viafc_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\SubscriberModel (BelongsTo viaowner_id)
Example:
php
// Accessing owner
$owner = $company->owner;notes
Access all notes for this company
- return
FluentCrm\App\Models\CompanyNoteModel 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();