41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Tenant;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TaskResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$assignedEventsCount = $this->relationLoaded('assignedEvents')
|
|
? $this->assignedEvents->count()
|
|
: $this->assignedEvents()->count();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'tenant_id' => $this->tenant_id,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'priority' => $this->priority,
|
|
'due_date' => $this->due_date?->toISOString(),
|
|
'is_completed' => (bool) $this->is_completed,
|
|
'collection_id' => $this->collection_id,
|
|
'assigned_events_count' => $assignedEventsCount,
|
|
'assigned_events' => $this->whenLoaded(
|
|
'assignedEvents',
|
|
fn () => EventResource::collection($this->assignedEvents)
|
|
),
|
|
'created_at' => $this->created_at?->toISOString(),
|
|
'updated_at' => $this->updated_at?->toISOString(),
|
|
];
|
|
}
|
|
}
|
|
|