<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * 前台用户扩展数据
 *
 * 存储前台用户(users)的扩展字段实际值，
 * 每个用户+字段一条记录。
 */
class UserExtData extends BaseModel
{
    protected $table = 'user_ext_data';

    public const CREATED_AT = 'create_time';
    public const UPDATED_AT = 'update_time';

    protected $fillable = [
        'user_id',
        'field_id',
        'field_value',
    ];

    protected $casts = [
        'user_id' => 'integer',
        'field_id' => 'integer',
    ];

    /**
     * 关联前台用户
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    /**
     * 关联字段定义
     */
    public function field(): BelongsTo
    {
        return $this->belongsTo(UserExtField::class, 'field_id');
    }
}
