input('name'); $groups = AssetGroup::where('name', 'like', "%{$name}%")->orderByDesc("sequence")->get(); return AssetGroupResource::collection($groups); } /** * Store a newly created resource in storage. */ public function store(CreateOrUpdateRequest $request) { AssetGroup::create([ ...$request->all(), 'company_id' => Auth::user()->company_id, ]); return $this->created(); } /** * Display the specified resource. */ public function show(string $id) { $asset = AssetGroup::findOrFail($id); return new AssetGroupResource($asset); } /** * Update the specified resource in storage. */ public function update(CreateOrUpdateRequest $request, string $id) { $group = AssetGroup::query()->findOrFail($id); $group->fill($request->only( 'name', 'sequence' )); $group->save(); return $this->noContent(); } /** * Remove the specified resource from storage. */ public function destroy(string $id) { $group = AssetGroup::query()->findOrFail($id); if(($group->assets)->isEmpty()){ $group->delete(); } else{ throw new \Exception("资产分组下还绑定了资产,不能删除。"); } $group->delete(); return $this->noContent(); } }