success( Tool::whereUserId($request->user('api')->id)->get() ); } /** * Store a newly created resource in storage. * * @throws \Exception */ public function store(Request $request) { $request->validate([ 'name' => 'string|required', 'description' => 'string|nullable', 'url' => 'string|required', 'api_key' => 'string|nullable', ]); $url = $request->input('url'); // 检测是否存在 if (Tool::whereDiscoveryUrl($url)->exists()) { return $this->conflict('The tool already exists'); } $json = Http::get($url); $tool = new Tool(); $tool = $tool->create([ 'name' => '', 'description' => '', 'discovery_url' => $url, 'api_key' => $request->input('api_key'), 'user_id' => $request->user('api')->id, ]); $toolRepo = new ToolRepo($tool->id, $json->json()); $tool->update([ 'name' => $toolRepo->name, 'description' => $toolRepo->description, 'data' => $toolRepo, ]); return $this->created($tool); } /** * Display the specified resource. */ public function show(ToolRequest $request, Tool $tool) { return $this->success($tool); } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(ToolRequest $request, Tool $tool) { $tool->delete(); return $this->deleted(); } }