Files
muninn/app/Http/Resources/ProjectResource.php
T

27 lines
965 B
PHP
Raw Normal View History

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProjectResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'status' => $this->status,
'due_at' => $this->due_at?->toIso8601String(),
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String(),
'deleted_at' => $this->deleted_at?->toIso8601String(),
'task_count' => $this->whenLoaded('tasks', fn () => $this->tasks->count()),
'active_task_count' => $this->whenLoaded('tasks', fn () => $this->activeTasks->count()),
'completed_task_count' => $this->whenLoaded('tasks', fn () => $this->completedTasks->count()),
];
}
}