<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use phpDocumentor\Reflection\Types\Self_;

class UserRole extends Model
{
    protected $table    = 'users_role';
    protected $fillable = ['user_id', 'name', 'sex', 'age', 'star', 'level'];

//    public function getSexAttribute($res)
//    {
//        return '男' == $res ? '男孩' : '女孩';
//    }
    public static $level = [0 => '幼儿园',1 => '一年级',2 => '二年级',3 => '三年级',4 => '四年级',5 => '五年级',6 => '六年级'];
    public function getLevelAtAttribute($value)
    {
        if (is_int($value)) return self::$level[$value];
        return $value;
    }
    public function userData(){
        return $this->hasOne(User::class,'id','user_id');
    }
    public function getCreatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }

    public function getUpdatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }
}
