Files
chatroom/app/Models/UserIdentityBadge.php
T

66 lines
1.4 KiB
PHP

<?php
/**
* 文件功能:用户身份徽章模型。
*
* 管理用户从签到等来源获得的当前身份展示标识。
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 类功能:封装用户身份徽章字段、类型转换与用户关联。
*/
class UserIdentityBadge extends Model
{
/** @use HasFactory<\Database\Factories\UserIdentityBadgeFactory> */
use HasFactory;
public const SOURCE_SIGN_IN = 'sign_in';
/**
* 允许批量赋值的字段。
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'source',
'badge_code',
'badge_name',
'badge_icon',
'badge_color',
'acquired_at',
'expires_at',
'is_active',
'metadata',
];
/**
* 属性类型转换。
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'acquired_at' => 'datetime',
'expires_at' => 'datetime',
'is_active' => 'boolean',
'metadata' => 'array',
];
}
/**
* 关联:身份徽章所属用户。
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}