get('page_size') ?? 10; $groups = RequirementGroup::filter($request->all())->where("parent_id",0)->with(['children','asset'])->paginate($pageSize); return RequirementGroupResource::collection($groups); } //公共RequirementGroup查询 public function publicSearch(Request $request) { $groups = RequirementGroup::filter($request->all())->where("parent_id",0)->with(['children'])->get(); return RequirementGroupResource::collection($groups); } /** * Store a newly created resource in storage. */ public function store(CreateOrUpdateRequest $request) { RequirementGroup::create([ ...$request->all(), 'company_id' => Auth::user()->company_id, ]); return $this->created(); } /** * Display the specified resource. */ public function show(string $id) { $groups = RequirementGroup::findOrFail($id); return new RequirementGroupResource($groups); } /** * Update the specified resource in storage. */ public function update(CreateOrUpdateRequest $request, string $id) { $group = RequirementGroup::query()->findOrFail($id); $group->fill($request->all()); $group->save(); return $this->noContent(); } /** * Remove the specified resource from storage. */ public function destroy(string $id) { $group = RequirementGroup::query()->findOrFail($id); if(empty($group->children()->first())){ $group->delete(); } else{ throw new \Exception("Please remove the sub-level requirementGroup"); } return $this->noContent(); } }