69 lines
1.4 KiB
PHP
69 lines
1.4 KiB
PHP
<?php
|
|
// app/Models/Review.php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Review extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'reviews';
|
|
|
|
protected $fillable = [
|
|
'review',
|
|
'text_final',
|
|
'score',
|
|
'sentiment'
|
|
];
|
|
|
|
protected $casts = [
|
|
'score' => 'integer',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime'
|
|
];
|
|
|
|
/**
|
|
* Scope untuk filter sentimen positif
|
|
*/
|
|
public function scopePositif($query)
|
|
{
|
|
return $query->where('sentiment', 'positif');
|
|
}
|
|
|
|
/**
|
|
* Scope untuk filter sentimen negatif
|
|
*/
|
|
public function scopeNegatif($query)
|
|
{
|
|
return $query->where('sentiment', 'negatif');
|
|
}
|
|
|
|
/**
|
|
* Scope untuk filter berdasarkan score
|
|
*/
|
|
public function scopeScoreRange($query, $min, $max)
|
|
{
|
|
return $query->whereBetween('score', [$min, $max]);
|
|
}
|
|
|
|
/**
|
|
* Get sentiment badge class untuk styling
|
|
*/
|
|
public function getSentimentBadgeClassAttribute()
|
|
{
|
|
return $this->sentiment === 'positif'
|
|
? 'bg-green-100 text-green-800'
|
|
: 'bg-red-100 text-red-800';
|
|
}
|
|
|
|
/**
|
|
* Get sentiment in uppercase
|
|
*/
|
|
public function getSentimentUppercaseAttribute()
|
|
{
|
|
return strtoupper($this->sentiment);
|
|
}
|
|
} |