Browse Source

部门和任务的返回children调整

kely 11 months ago
parent
commit
ced5372294

+ 1 - 1
app/Http/Controllers/API/DepartmentController.php

@@ -14,7 +14,7 @@ class DepartmentController extends Controller
 
     public function index(Request $request)
     {
-        $department=Department::filter($request->all())->where("parent_id",0)->with(['children'])->simplePaginate();
+        $department=Department::filter($request->all())->where("parent_id",0)->with(['children'])->paginate();
 
         return DepartmentResource::collection($department);
     }

+ 5 - 1
app/Http/Resources/API/DepartmentResource.php

@@ -19,7 +19,11 @@ class DepartmentResource extends JsonResource
           'id' => $this->id,
           'name' => $this->name,
           'parent_id'  => $this->parent_id,
-          'children' => $this->parent_id == 0 ? DepartmentResource::collection($this->children) : [],
+          'children' => $this->when($this->children->isNotEmpty(),function (){
+                return $this->children->map(function ($child){
+                    return new DepartmentResource($child);
+                })->all();
+            }),
         ];
     }
 }

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

@@ -23,7 +23,12 @@ class TaskResource extends JsonResource
             "status" => $this->status,
             "assign_to" => new UserProfileResource($this->assignTo),
             "created_by" => new UserProfileResource($this->createdBy),
-            "children" => TaskResource::collection($this->children),
+            //"children" => TaskResource::collection($this->children),
+            'children' => $this->when($this->children->isNotEmpty(),function (){
+                return $this->children->map(function ($child){
+                    return new TaskResource($child);
+                })->all();
+            }),
         ];
     }
 }