Browse Source

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

kely 1 year ago
parent
commit
7d5e35e5d3

+ 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);
     }