78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ForumPost extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'forum_posts';
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'thread_id',
|
|
'topic_id',
|
|
'user_id',
|
|
'content',
|
|
'is_edited',
|
|
'edited_at',
|
|
'spam_score',
|
|
'quality_score',
|
|
'flagged',
|
|
'flagged_reason',
|
|
'moderation_checked',
|
|
];
|
|
|
|
public $incrementing = true;
|
|
|
|
protected $casts = [
|
|
'is_edited' => 'boolean',
|
|
'edited_at' => 'datetime',
|
|
'spam_score' => 'integer',
|
|
'quality_score' => 'integer',
|
|
'flagged' => 'boolean',
|
|
'moderation_checked' => 'boolean',
|
|
];
|
|
|
|
public function thread(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ForumThread::class, 'thread_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function attachments(): HasMany
|
|
{
|
|
return $this->hasMany(ForumAttachment::class, 'post_id');
|
|
}
|
|
|
|
public function scopeInThread(Builder $query, int $threadId): Builder
|
|
{
|
|
return $query->where('thread_id', $threadId);
|
|
}
|
|
|
|
public function scopeVisible(Builder $query): Builder
|
|
{
|
|
return $query;
|
|
}
|
|
|
|
public function scopePinned(Builder $query): Builder
|
|
{
|
|
return $query->whereHas('thread', fn (Builder $threadQuery) => $threadQuery->where('is_pinned', true));
|
|
}
|
|
|
|
public function scopeRecent(Builder $query): Builder
|
|
{
|
|
return $query->orderByDesc('created_at')->orderByDesc('id');
|
|
}
|
|
}
|