2026-02-06 15:13:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
class Comment extends Model
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array<int, string>
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'user_id',
|
|
|
|
|
'product_id',
|
|
|
|
|
'body',
|
2026-02-21 15:50:32 +02:00
|
|
|
'status',
|
|
|
|
|
'moderated_by',
|
|
|
|
|
'moderated_at',
|
|
|
|
|
'moderation_note',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @var array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'moderated_at' => 'datetime',
|
2026-02-06 15:13:20 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user that owns the comment.
|
|
|
|
|
*/
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the product that owns the comment.
|
|
|
|
|
*/
|
|
|
|
|
public function product(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Product::class);
|
|
|
|
|
}
|
2026-02-21 15:50:32 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the moderator who moderated the comment.
|
|
|
|
|
*/
|
|
|
|
|
public function moderator(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'moderated_by');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if comment is pending moderation.
|
|
|
|
|
*/
|
|
|
|
|
public function isPending(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->status === 'pending';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if comment is approved.
|
|
|
|
|
*/
|
|
|
|
|
public function isApproved(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->status === 'approved';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if comment is rejected.
|
|
|
|
|
*/
|
|
|
|
|
public function isRejected(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->status === 'rejected';
|
|
|
|
|
}
|
2026-02-06 15:13:20 +02:00
|
|
|
}
|