Skip to main content

Recording Model

The Recording model represents audio recordings in the system, including call recordings and uploaded audio files for IVR/music on hold.

Overview

PropertyValue
NamespaceApp\Models
Tablerecordings
Primary Keyid
Global ScopeOrganizationScope

Database Schema

ColumnTypeNullableDescription
idbigint unsignedNoPrimary key
organization_idbigint unsignedNoOrganization ID
namevarchar(255)NoRecording name
typeenum(upload,remote)NoRecording type
file_pathvarchar(500)YesLocal file path
remote_urlvarchar(500)YesRemote URL
original_filenamevarchar(255)YesOriginal filename
file_sizebigint unsignedYesFile size in bytes
mime_typevarchar(100)YesMIME type
duration_secondsintYesDuration in seconds
statusvarchar(50)Noactive/inactive
created_bybigint unsignedYesCreator user ID
updated_bybigint unsignedYesUpdater user ID
created_attimestampNoCreation timestamp
updated_attimestampNoUpdate timestamp

Recording Types

TypeDescription
uploadFile uploaded to local storage
remoteExternal 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

AttributeCastDescription
file_sizeintegerInteger cast
duration_secondsintegerInteger cast
statusstringString cast
typestringString cast

Relationships

Belongs To

  • organization() → Organization
  • creator() → 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...