CallDetailRecord Model
The CallDetailRecord (CDR) model stores detailed call records received from Cloudonix at the end of each call. CDRs contain billing information, call metrics, and quality of service data.
Overview
| Property | Value |
|---|---|
| Namespace | App\Models |
| Table | call_detail_records |
| Primary Key | id |
Database Schema
| Column | Type | Nullable | Description |
|---|---|---|---|
id | bigint unsigned | No | Primary key |
organization_id | bigint unsigned | No | Organization ID |
session_timestamp | datetime | No | Session timestamp |
session_token | varchar(255) | Yes | Session token |
from | varchar(100) | No | Caller number |
to | varchar(100) | No | Called number |
disposition | varchar(50) | No | Call disposition |
duration | int | No | Total duration in seconds |
billsec | int | No | Billable duration in seconds |
call_id | varchar(255) | No | SIP Call-ID |
domain | varchar(255) | Yes | Cloudonix domain |
subscriber | varchar(100) | Yes | Subscriber identifier |
cx_trunk_id | int | Yes | Cloudonix trunk ID |
application | varchar(255) | Yes | Application name |
route | varchar(255) | Yes | Route name |
rated_cost | decimal(10,4) | Yes | Rated call cost |
approx_cost | decimal(10,4) | Yes | Approximate cost |
sell_cost | decimal(10,4) | Yes | Sell cost |
vapp_server | varchar(50) | Yes | VApp server |
session_id | int | Yes | Session ID |
call_start_time | datetime | Yes | Call start time |
call_end_time | datetime | Yes | Call end time |
call_answer_time | datetime | Yes | Call answer time |
status | varchar(50) | Yes | Call status |
raw_cdr | json | No | Complete raw CDR JSON |
created_at | timestamp | No | Creation timestamp |
updated_at | timestamp | No | Update timestamp |
Attributes
Fillable
protected $fillable = [
'organization_id',
'session_timestamp',
'session_token',
'from',
'to',
'disposition',
'duration',
'billsec',
'call_id',
'domain',
'subscriber',
'cx_trunk_id',
'application',
'route',
'rated_cost',
'approx_cost',
'sell_cost',
'vapp_server',
'session_id',
'call_start_time',
'call_end_time',
'call_answer_time',
'status',
'raw_cdr',
];
Casts
| Attribute | Cast | Description |
|---|---|---|
session_timestamp | datetime | Carbon instance |
call_start_time | datetime | Carbon instance |
call_end_time | datetime | Carbon instance |
call_answer_time | datetime | Carbon instance |
duration | integer | Integer cast |
billsec | integer | Integer cast |
cx_trunk_id | integer | Integer cast |
session_id | integer | Integer cast |
rated_cost | decimal:4 | Decimal with 4 places |
approx_cost | decimal:4 | Decimal with 4 places |
sell_cost | decimal:4 | Decimal with 4 places |
raw_cdr | array | JSON data |
Relationships
Belongs To
organization()→ Organization
Methods
Factory Method
createFromWebhook(array $payload, int $organizationId): self
Create a CDR from Cloudonix webhook payload.
$cdr = CallDetailRecord::createFromWebhook($payload, $organizationId);
Accessors
getFormattedDurationAttribute(): string
Get formatted duration as MM:SS.
$cdr->formatted_duration; // "05:30"
getFormattedBillsecAttribute(): string
Get formatted billable duration as MM:SS.
$cdr->formatted_billsec; // "05:15"
Query Scopes
scopeForOrganization($query, int $organizationId)scopeWithDisposition($query, string $disposition)scopeConnected($query)- Connected calls onlyscopeBetweenDates($query, Carbon $startDate, Carbon $endDate)
Dispositions
| Disposition | Description |
|---|---|
CONNECTED | Call was connected |
NO_ANSWER | No answer |
BUSY | Line busy |
FAILED | Call failed |
CANCELLED | Call cancelled |
Usage Examples
Creating from Webhook
$payload = [
'timestamp' => 1705312800,
'from' => '+1234567890',
'to' => '+1987654321',
'disposition' => 'CONNECTED',
'duration' => 300,
'billsec' => 295,
'call_id' => 'CA550e8400e29b41d4a716446655440000',
'session' => [
'id' => 12345,
'token' => 'sess_token',
'callStartTime' => 1705312800000,
'callEndTime' => 1705313100000,
'callAnswerTime' => 1705312815000,
],
];
$cdr = CallDetailRecord::createFromWebhook($payload, $orgId);
Querying CDRs
use Carbon\Carbon;
// Get connected calls for organization
$connected = CallDetailRecord::connected()
->forOrganization($orgId)
->get();
// Get calls in date range
$cdrs = CallDetailRecord::betweenDates(
Carbon::parse('2024-01-01'),
Carbon::parse('2024-01-31')
)->get();
// Get specific disposition
$failed = CallDetailRecord::withDisposition('FAILED')->get();