hasHeader('Authorization')) { $guards = array_keys(config('auth.guards')); if (empty($guards)) { $guards = [null]; } foreach ($guards as $guard) { if (Auth::guard($guard)->check()) { Auth::shouldUse($guard); break; } } if (! Auth::check()) { throw new AuthenticationException('Authentication failed.'); } } try { /** @var User $user */ $user = Auth::user(); $image = $service->store($request, $user); } catch (UploadException $e) { return $this->error($e->getMessage()); } catch (\Throwable $e) { Log::error("Api 上传文件时发生异常,", ['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); if (config('app.debug')) { return $this->error($e->getMessage()); } return $this->error('服务异常,请稍后再试'); } return $this->success('上传成功', $image->setAppends(['pathname', 'links'])->only( 'key', 'name', 'extension', 'pathname', 'origin_name', 'size', 'mimetype', 'md5', 'sha1', 'links' )); } public function images(Request $request): Response { } }