'integer', 'user_id' => 'integer', ]; public const STATUS_PENDING = 'pending'; public const STATUS_APPROVED = 'approved'; public const STATUS_REJECTED = 'rejected'; /** * 可见性作用域(同 ForumThread): * - 审核员:全部 * - 登录用户:已审 + 自己发的 * - 游客:仅已审 */ public function scopeVisible($query, ?User $user = null) { if ($user && $user->canPerm('forum.moderate')) { return $query; } if ($user) { return $query->where(function ($q) use ($user) { $q->where('status', self::STATUS_APPROVED) ->orWhere('user_id', $user->id); }); } return $query->where('status', self::STATUS_APPROVED); } public function thread(): BelongsTo { return $this->belongsTo(ForumThread::class, 'thread_id'); } public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } }