'boolean', 'reviewed_at' => 'datetime', ]; const RATING_HELPFUL = 'helpful'; const RATING_NOT_HELPFUL = 'not_helpful'; const RATING_PARTIALLY_HELPFUL = 'partially_helpful'; // === Relationships === public function chatLog(): BelongsTo { return $this->belongsTo(ChatLog::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function reviewer(): BelongsTo { return $this->belongsTo(User::class, 'reviewed_by'); } public function convertedFaq(): BelongsTo { return $this->belongsTo(KnowledgeItem::class, 'converted_faq_id'); } // === Scopes === public function scopeNegative(Builder $query): Builder { return $query->where('rating', self::RATING_NOT_HELPFUL); } public function scopeNotConverted(Builder $query): Builder { return $query->where('converted_to_faq', false) ->where('rating', '!=', self::RATING_HELPFUL); } public function scopeUnreviewed(Builder $query): Builder { return $query->whereNull('reviewed_by'); } }