'boolean', 'ai_confidence' => 'float', 'confidence' => 'decimal:2', 'sequence' => 'integer', 'order' => 'integer', 'options' => 'array', 'images' => 'array', 'tables' => 'array', 'formula_detected' => 'boolean', 'is_valid_question' => 'boolean', 'meta' => 'array', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; public const STATUS_PENDING = 'pending'; public const STATUS_REVIEWED = 'reviewed'; public const STATUS_ACCEPTED = 'accepted'; public const STATUS_REJECTED = 'rejected'; public const STATUS_SUPERSEDED = 'superseded'; public function import(): BelongsTo { return $this->belongsTo(MarkdownImport::class, 'import_id'); } public function sourceFile(): BelongsTo { return $this->belongsTo(SourceFile::class, 'source_file_id'); } public function sourcePaper(): BelongsTo { return $this->belongsTo(SourcePaper::class, 'source_paper_id'); } public function part(): BelongsTo { return $this->belongsTo(PaperPart::class, 'part_id'); } public function getConfidenceBadgeAttribute(): string { if ($this->ai_confidence === null) { return 'gray'; } if ($this->ai_confidence >= 0.8) { return 'success'; } elseif ($this->ai_confidence >= 0.5) { return 'warning'; } return 'danger'; } public function getStatusBadgeAttribute(): string { $badges = [ self::STATUS_PENDING => 'gray', self::STATUS_REVIEWED => 'info', self::STATUS_ACCEPTED => 'success', self::STATUS_REJECTED => 'danger', self::STATUS_SUPERSEDED => 'gray', ]; return $badges[$this->status] ?? 'gray'; } public function getFirstImageAttribute(): ?string { if (empty($this->images)) { return null; } $images = is_string($this->images) ? json_decode($this->images, true) : $this->images; return $images[0] ?? null; } public function getStemPreviewAttribute(): string { if (!$this->stem) { return 'No stem extracted'; } return \Str::limit($this->stem, 100); } /** * 重写getKey方法,确保返回字符串类型 * 解决Filament表格渲染时的TypeError问题 */ public function getKey(): int|string { $key = parent::getKey(); // 如果键值为null,返回一个默认值(基于时间戳和随机数) if ($key === null) { return 'temp_' . time() . '_' . mt_rand(1000, 9999); } return $key; } /** * 重写getKeyName方法,返回主键名称 */ public function getKeyName(): string { return 'id'; } }