First commit
This commit is contained in:
71
app/Models/ChatFeedback.php
Normal file
71
app/Models/ChatFeedback.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ChatFeedback extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'chat_log_id',
|
||||
'user_id',
|
||||
'rating',
|
||||
'comment',
|
||||
'correct_answer',
|
||||
'converted_to_faq',
|
||||
'converted_faq_id',
|
||||
'reviewed_by',
|
||||
'reviewed_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'converted_to_faq' => '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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user