# API 连接问题修复报告 ## 问题描述 FilamentAdmin 访问时出现以下错误: 1. **TypeError**: `FilamentManager::getUserName()` 返回 null 而不是 string 2. **ConnectionException**: 无法连接到 `127.0.0.1:5015` (Question Bank API) ## 修复内容 ### 1. User 模型 TypeError 修复 **文件**: `/Volumes/T9/code/math/apis/FilamentAdmin/app/Models/User.php` **问题**: User 表使用 `full_name` 字段,但 Filament 尝试访问 `name` 字段返回 null **解决方案**: - 导入 `HasName` 接口 - 让 User 类实现 `FilamentUser, HasName` 接口 - 添加 `getFilamentName()` 方法 ```php class User extends Authenticatable implements FilamentUser, HasName { public function getFilamentName(): string { return $this->full_name ?: $this->username ?: $this->email ?: 'Unknown User'; } } ``` ### 2. Question Bank API 端口修复 **文件**: `/Volumes/T9/code/math/apis/docker-compose.microservices.yml` **问题**: `api-question-bank` 服务没有暴露外部端口 5015 **解决方案**: - 添加端口映射: `"5015:5015"` ### 3. Question Bank Service 端口修复 **文件**: `/Volumes/T9/code/math/apis/QuestionBankService/Dockerfile` **问题**: 容器内应用运行在 6001 端口,但外部访问需要 5015 端口 **解决方案**: - 修改端口配置: `EXPOSE 5015` 和 `--port 5015` ### 4. Knowledge API 端口修复 **文件**: `/Volumes/T9/code/math/apis/docker-compose.microservices.yml` **问题**: `api-knowledge` 服务没有暴露外部端口 5011 **解决方案**: - 添加端口映射: `"5011:5011"` ### 5. Nginx 依赖修复 **文件**: `/Volumes/T9/code/math/apis/docker-compose.microservices.yml` **问题**: nginx 服务依赖 `filament-admin`,但该服务已禁用 **解决方案**: - 注释掉 nginx 服务配置 ## 服务状态验证 所有 API 服务现在正常工作: ```bash ✅ Question Bank API (5015): HTTP 200 GET http://127.0.0.1:5015/health GET http://127.0.0.1:5015/questions?page=1&per_page=5 ✅ Knowledge API (5011): HTTP 200 GET http://127.0.0.1:5011/health ✅ MathRecSys API (5010): HTTP 200 GET http://127.0.0.1:5010/health ``` ## 容器状态 ```bash api-question-bank 0.0.0.0:5015->5015/tcp api-knowledge 0.0.0.0:5011->5011/tcp mathrecsys-api 0.0.0.0:5010->5010/tcp mathrecsys-frontend 0.0.0.0:3000->3000/tcp ``` ## 测试步骤 1. 清理 Laravel 缓存: ```bash cd /Volumes/T9/code/math/apis/FilamentAdmin php artisan config:clear php artisan cache:clear ``` 2. 访问 FilamentAdmin: ``` http://fa.test/admin ``` 3. 验证 API 连接: ```bash curl http://127.0.0.1:5015/health curl http://127.0.0.1:5011/health curl http://127.0.0.1:5010/health ``` ## 修复时间 2025-11-17 13:10 ## 修复人 Claude Code