Files
besttechfrom.eu/app/Models/Comment.php
T

82 lines
1.5 KiB
PHP

<?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',
'status',
'moderated_by',
'moderated_at',
'moderation_note',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'moderated_at' => 'datetime',
];
/**
* 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);
}
/**
* 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';
}
}