Recording Model
The Recording model represents audio recordings in the system, including call recordings and uploaded audio files for IVR/music on hold.
Overview
| Property | Value |
|---|---|
| Namespace | App\Models |
| Table | recordings |
| Primary Key | id |
| Global Scope | OrganizationScope |
Database Schema
| Column | Type | Nullable | Description |
|---|---|---|---|
id | bigint unsigned | No | Primary key |
organization_id | bigint unsigned | No | Organization ID |
name | varchar(255) | No | Recording name |
type | enum(upload,remote) | No | Recording type |
file_path | varchar(500) | Yes | Local file path |
remote_url | varchar(500) | Yes | Remote URL |
original_filename | varchar(255) | Yes | Original filename |
file_size | bigint unsigned | Yes | File size in bytes |
mime_type | varchar(100) | Yes | MIME type |
duration_seconds | int | Yes | Duration in seconds |
status | varchar(50) | No | active/inactive |
created_by | bigint unsigned | Yes | Creator user ID |
updated_by | bigint unsigned | Yes | Updater user ID |
created_at | timestamp | No | Creation timestamp |
updated_at | timestamp | No | Update timestamp |
Recording Types
| Type | Description |
|---|---|
upload | File uploaded to local storage |
remote | External URL reference |
Attributes
Fillable
protected $fillable = [
'organization_id',
'name',
'type',
'file_path',
'remote_url',
'original_filename',
'file_size',
'mime_type',
'duration_seconds',
'status',
'created_by',
'updated_by',
];
Casts
| Attribute | Cast | Description |
|---|---|---|
file_size | integer | Integer cast |
duration_seconds | integer | Integer cast |
status | string | String cast |
type | string | String cast |
Relationships
Belongs To
organization()→ Organizationcreator()→ User (created_by)updater()→ User (updated_by)
Methods
Type Checking
isActive(): bool
Check if recording is active.
if ($recording->isActive()) {
// Recording is available
}
isUploaded(): bool
Check if recording is an uploaded file.
if ($recording->isUploaded()) {
// Local file storage
}
isRemote(): bool
Check if recording is a remote URL.
if ($recording->isRemote()) {
// External URL
}
URL Generation
getPlaybackUrl(int $userId): string
Get token-secured playback URL.
$url = $recording->getPlaybackUrl($userId);
getDownloadUrl(int $userId): string
Get token-secured download URL.
$url = $recording->getDownloadUrl($userId);
Formatting
getFormattedFileSize(): string
Get human-readable file size.
$size = $recording->getFormattedFileSize(); // "5.25 MB"
getFormattedDuration(): string
Get formatted duration as MM:SS.
$duration = $recording->getFormattedDuration(); // "03:45"
Usage Examples
Creating an Uploaded Recording
use App\Models\Recording;
$recording = Recording::create([
'organization_id' => $orgId,
'name' => 'Welcome Message',
'type' => 'upload',
'file_path' => 'recordings/2024/01/audio123.mp3',
'original_filename' => 'welcome.mp3',
'file_size' => 5242880,
'mime_type' => 'audio/mpeg',
'duration_seconds' => 225,
'status' => 'active',
'created_by' => $userId,
]);
Creating a Remote Recording
$recording = Recording::create([
'organization_id' => $orgId,
'name' => 'Hold Music',
'type' => 'remote',
'remote_url' => 'https://cdn.example.com/music/hold.mp3',
'status' => 'active',
'created_by' => $userId,
]);
Getting Playback URL
// Get secure playback URL
$playbackUrl = $recording->getPlaybackUrl(auth()->id());
// Returns token-based URL like:
// https://api.example.com/api/v1/recordings/download?token=abc123...