label('新建系列') ->mutateFormDataUsing(function (array $data): array { // 调用 API 创建教材系列 try { $apiService = app(TextbookApiService::class); $result = $apiService->createTextbookSeries($data); if ($result) { Notification::make() ->title('教材系列创建成功') ->success() ->send(); } return $data; } catch (\Exception $e) { Notification::make() ->title('教材系列创建失败') ->body($e->getMessage()) ->danger() ->send(); return $data; } }), ]; } protected function mutateTableQueryUsing(Builder $query): Builder { // 由于数据在 PostgreSQL 中,这里返回空查询 // 实际数据通过 API 获取 return $query->whereRaw('1=0'); } public function mount(): void { parent::mount(); // 初始化时从 API 获取数据 $this->refreshTableDataFromApi(); } protected function refreshTableDataFromApi(): void { // 通过 API 获取教材系列数据 try { $apiService = app(TextbookApiService::class); $seriesData = $apiService->getTextbookSeries(); // 将 API 数据转换为 Eloquent 集合(用于显示) // 这里需要根据实际 API 响应格式调整 // 由于 Filament 表格需要 Eloquent 模型,这里只是示例 // 实际项目中可能需要创建临时的资源类来处理 API 数据 } catch (\Exception $e) { Notification::make() ->title('获取数据失败') ->body($e->getMessage()) ->danger() ->send(); } } }