'datetime', 'created_at' => 'datetime', ]; } // ────────────────────────────────────────── // 公共查询方法 // ────────────────────────────────────────── /** * 判断给定名称是否被禁止使用。 * * 满足以下任一条件时返回 true: * 1. 存在 type=permanent 的永久禁用记录 * 2. 存在 type=temp 且 reserved_until 尚未过期的临时保留记录 * * @param string $username 要检测的用户名 */ public static function isBlocked(string $username): bool { return static::where('username', $username) ->where(function ($q) { // 永久禁用 $q->where('type', 'permanent') // 或:临时保留且尚未到期 ->orWhere(function ($q2) { $q2->where('type', 'temp') ->where('reserved_until', '>', now()); }); }) ->exists(); } /** * 兼容旧调用:isReserved() 等同于 isBlocked()。 * * @param string $username 要检测的用户名 * * @deprecated 请使用 isBlocked() */ public static function isReserved(string $username): bool { return static::isBlocked($username); } // ────────────────────────────────────────── // 作用域(Scopes) // ────────────────────────────────────────── /** * 仅查询永久禁用词(管理员维护的列表)。 */ public function scopePermanent($query) { return $query->where('type', 'permanent'); } /** * 仅查询临时保留记录(改名后旧名)。 */ public function scopeTemp($query) { return $query->where('type', 'temp'); } }