Files
chatroom/app/Models/UsernameBlacklist.php

35 lines
819 B
PHP

<?php
/**
* 文件功能:用户名黑名单模型
* 用户改名后旧名称写入此表,保留期间其他人无法注册该名称
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UsernameBlacklist extends Model
{
protected $table = 'username_blacklist';
public $timestamps = false; // 只有 created_at 无 updated_at
protected $fillable = ['username', 'reserved_until', 'created_at'];
protected $casts = [
'reserved_until' => 'datetime',
'created_at' => 'datetime',
];
/**
* 判断给定名称是否在黑名单有效期内
*/
public static function isReserved(string $username): bool
{
return static::where('username', $username)
->where('reserved_until', '>', now())
->exists();
}
}