['text' => 'Peasant'], self::CLASS_USER => ['text' => 'User'], self::CLASS_POWER_USER => ['text' => 'Power User'], self::CLASS_ELITE_USER => ['text' => 'Elite User'], self::CLASS_CRAZY_USER => ['text' => 'Crazy User'], self::CLASS_INSANE_USER => ['text' => 'Insane User'], self::CLASS_VETERAN_USER => ['text' => 'Veteran User'], self::CLASS_EXTREME_USER => ['text' => 'Extreme User'], self::CLASS_ULTIMATE_USER => ['text' => 'Ultimate User'], self::CLASS_NEXUS_MASTER => ['text' => 'Nexus Master'], self::CLASS_VIP => ['text' => 'Vip'], self::CLASS_RETIREE => ['text' => 'Retiree'], self::CLASS_UPLOADER => ['text' => 'Uploader'], self::CLASS_MODERATOR => ['text' => 'Moderator'], self::CLASS_ADMINISTRATOR => ['text' => 'Administrator'], self::CLASS_SYSOP => ['text' => 'Sysop'], self::CLASS_STAFF_LEADER => ['text' => 'Staff Leader'], ]; public function getClassTextAttribute(): string { return self::$classes[$this->class]['text'] ?? ''; } /** * 为数组 / JSON 序列化准备日期。 * * @param \DateTimeInterface $date * @return string */ protected function serializeDate(\DateTimeInterface $date): string { return $date->format($this->dateFormat ?: 'Y-m-d H:i:s'); } /** * The attributes that are mass assignable. * * @var array */ protected $fillable = ['username', 'email', 'passhash', 'secret', 'editsecret', 'added']; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'secret', 'passhash', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'added' => 'datetime', ]; public static $commonFields = [ 'id', 'username', 'email', 'class', 'status', 'added', 'avatar', 'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime', 'invited_by', ]; public function checkIsNormal(array $fields = ['status', 'enabled']) { if (in_array('visible', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) { throw new \InvalidArgumentException(sprintf('User: %s is not confirmed.', $this->id)); } if (in_array('enabled', $fields) && $this->getAttribute('enabled') != self::ENABLED_YES) { throw new \InvalidArgumentException(sprintf('User: %s is not enabled.', $this->id)); } return true; } public function getLocaleAttribute() { return Locale::$languageMaps[$this->language->site_lang_folder] ?? 'en'; } public function exams() { return $this->hasMany(ExamUser::class, 'uid'); } public function language() { return $this->belongsTo(Language::class, 'lang'); } public function invitee_code() { return $this->hasOne(Invite::class, 'invitee_register_uid'); } public function inviter() { return $this->belongsTo(User::class, 'invited_by'); } }