41 خطوط
1.8 KiB
PHP
41 خطوط
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class CallResource extends JsonResource
|
|
{
|
|
public static $wrap = null;
|
|
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'lead_id' => $this->lead_id,
|
|
'lead' => $this->whenLoaded('lead', fn () => $this->lead?->only(['id', 'first_name', 'last_name', 'company', 'phone'])),
|
|
'contact_id' => $this->contact_id,
|
|
'contact' => $this->whenLoaded('contact', fn () => $this->contact?->only(['id', 'name', 'role'])),
|
|
'contact_phone_id' => $this->contact_phone_id,
|
|
'contact_phone' => $this->whenLoaded('contactPhone', fn () => $this->contactPhone?->only(['id', 'phone', 'type', 'status'])),
|
|
'user_id' => $this->user_id,
|
|
'agent' => $this->whenLoaded('user', fn () => $this->user?->only(['id', 'name'])),
|
|
'direction' => $this->direction,
|
|
'status' => $this->provider_status === 'completed' || $this->result ? 'completed' : 'pending',
|
|
'provider_status' => $this->provider_status,
|
|
'phone' => $this->phone,
|
|
'duration_seconds' => (int) $this->duration,
|
|
'result' => $this->result,
|
|
'notes' => $this->notes,
|
|
'provider_call_id' => $this->provider_call_id,
|
|
'recording_url' => $this->recording_url,
|
|
'is_manual' => (bool) $this->is_manual,
|
|
'started_at' => optional($this->started_at ?? $this->created_at)->toISOString(),
|
|
'ended_at' => optional($this->ended_at)->toISOString(),
|
|
'created_at' => optional($this->created_at)->toISOString(),
|
|
'updated_at' => optional($this->updated_at)->toISOString(),
|
|
];
|
|
}
|
|
}
|