Files
test_bellis/laravel/app/Http/Resources/TaskResource.php
2026-02-18 19:54:52 +07:00

37 lines
832 B
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Task;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Task
*/
class TaskResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'is_done' => $this->is_done,
'due_at' => optional($this->due_at)?->toISOString(),
'created_at' => $this->created_at->toISOString(),
'updated_at' => $this->updated_at->toISOString(),
'tags' => TagResource::collection(
$this->whenLoaded('tags')
),
];
}
}