'integer', 'target_author' => 'integer', 'reporter_id' => 'integer', 'resolved_by' => 'integer', ]; /** * Relationship: Report belongs to the member who made it. */ public function reporter() { return $this->belongsTo(User::class, 'reporter_id', 'ID'); } /** * Reports still awaiting review for one target. */ public static function pendingFor(string $targetType, int $targetId) { return static::where('target_type', $targetType) ->where('target_id', $targetId) ->where('status', ReportStatus::PENDING->value) ->get(); } /** * How many people have reported this target and are still waiting. * * The number the auto-hide threshold is compared against. Counts rows, which * is the same as counting people because of the unique index. */ public static function pendingCount(string $targetType, int $targetId): int { return (int) static::where('target_type', $targetType) ->where('target_id', $targetId) ->where('status', ReportStatus::PENDING->value) ->count(); } /** * Whether this member already has a report in flight for this target. */ public static function alreadyReported(int $reporterId, string $targetType, int $targetId): bool { return static::where('reporter_id', $reporterId) ->where('target_type', $targetType) ->where('target_id', $targetId) ->count() > 0; } }