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); $toolRepo = new ToolRepo($json->json()); $tool = new Tool(); $tool->create([ 'name' => $toolRepo->name, 'description' => $toolRepo->description, 'discovery_url' => $url, 'api_key' => $request->input('api_key'), 'data' => $toolRepo, 'user_id' => $request->user('api')->id, ]); 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(); } }