12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Http\Resources\API;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class PlanResource 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,
- 'asset_id' => $this->asset_id,
- 'asset_name' => $this->asset ? $this->asset->name : null,
- 'parent_id' => $this->parent_id,
- 'requirement_total' => $this->requirements()->count(),
- 'project_total' => $this->projects()->count(),
- 'begin' => $this->begin,
- 'end' => $this->end,
- 'description' => $this->description,
- //'children' => $this->parent_id == 0 ? PlanResource::collection($this->children) : [],
- 'children' => $this->when($this->children->isNotEmpty(),function (){
- return $this->children->map(function ($child){
- return new PlanResource($child);
- })->all();
- }),
- 'asset' => new AssetParentResource($this->asset),
- ];
- }
- }
|