浏览代码

给需求和计划添加资产的父级懒加载

kely 1 年之前
父节点
当前提交
7d5e35e5d3
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 3 1
      app/Http/Controllers/API/PlanController.php
  2. 3 1
      app/Http/Controllers/API/RequirementController.php

+ 3 - 1
app/Http/Controllers/API/PlanController.php

@@ -18,7 +18,9 @@ class PlanController extends Controller
      */
     public function index(Request $request)
     {
-        $plans = Plan::filter($request->all())->where("parent_id", 0)->with(['children','asset'])->simplePaginate();
+        $plans = Plan::filter($request->all())->where("parent_id", 0)->with(['children','asset'=>function($query){
+            $query->with('parent');
+        }])->simplePaginate();
 
         return PlanResource::collection($plans);
 

+ 3 - 1
app/Http/Controllers/API/RequirementController.php

@@ -24,7 +24,9 @@ class RequirementController extends Controller
      */
     public function index(Request $request)
     {
-        $requirements=Requirement::filter($request->all())->where('company_id',Auth::user()->company_id)->with(['createdBy', 'plan','group']) ->simplePaginate();
+        $requirements=Requirement::filter($request->all())->where('company_id',Auth::user()->company_id)->with(['createdBy', 'plan','group','asset'=>function($query){
+            $query->with('parent');
+        }]) ->simplePaginate();
 
         return AssetRequirementResource::collection($requirements);
     }