42 خطوط
1.7 KiB
PHP
42 خطوط
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class FollowUpResource extends JsonResource
|
|
{
|
|
public static $wrap = null;
|
|
|
|
public function toArray(Request $request): array
|
|
{
|
|
$gate = Gate::forUser($request->user());
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'lead_id' => $this->lead_id,
|
|
'lead' => $this->whenLoaded('lead', fn () => $this->lead?->only(['id', 'first_name', 'last_name', 'company', 'phone'])),
|
|
'user_id' => $this->user_id,
|
|
'assignee' => $this->whenLoaded('user', fn () => $this->user?->only(['id', 'name'])),
|
|
'created_by' => $this->created_by,
|
|
'creator' => $this->whenLoaded('creator', fn () => $this->creator?->only(['id', 'name'])),
|
|
'call_id' => $this->call_id,
|
|
'source' => $this->source,
|
|
'scheduled_at' => optional($this->scheduled_at)->toISOString(),
|
|
'completed_at' => optional($this->completed_at)->toISOString(),
|
|
'notes' => $this->notes,
|
|
'status' => $this->status,
|
|
'is_overdue' => (bool) $this->is_overdue || ($this->status === 'pending' && $this->scheduled_at?->isPast()),
|
|
'capabilities' => [
|
|
'update' => $gate->allows('update', $this->resource),
|
|
'complete' => $gate->allows('complete', $this->resource),
|
|
'delete' => $gate->allows('delete', $this->resource),
|
|
],
|
|
'created_at' => optional($this->created_at)->toISOString(),
|
|
'updated_at' => optional($this->updated_at)->toISOString(),
|
|
];
|
|
}
|
|
}
|