Răsfoiți Sursa

更改需求,计划的树结构

kely 1 an în urmă
părinte
comite
a9e4b34ef6

+ 6 - 1
app/Http/Resources/API/PlanResource.php

@@ -24,7 +24,12 @@ class PlanResource extends JsonResource
             'begin' => $this->begin,
             'end' => $this->end,
             'description' => $this->description,
-            'children' => $this->parent_id == 0 ? PlanResource::collection($this->children) : [],
+            //'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();
+            })
         ];
     }
 }

+ 6 - 1
app/Http/Resources/API/RequirementGroupResource.php

@@ -22,7 +22,12 @@ class RequirementGroupResource extends JsonResource
             'asset_id'=>$this->asset_id,
             'abbr_name'=>$this->abbr_name,
             'parent_id' => $this->parent_id,
-            'children' =>$this->parent_id == 0 ? RequirementGroupResource::collection($this->children) : [],
+            //'children' =>$this->parent_id == 0 ? RequirementGroupResource::collection($this->children) : [],
+            'children' =>$this->when($this->children->isNotEmpty(),function (){
+                return $this->children->map(function ($child){
+                    return new RequirementGroupResource($child);
+                })->all();
+            })
         ];
     }
 }