<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Activitylog\Traits\LogsActivity;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable, SoftDeletes,LogsActivity;
    // 指定 LogsActivity 记录名
    protected static $logName = 'Model';
    protected static $logAttributes = ['*'];
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'mobile', 'password', 'pid', 'tencent_im_user_id','sex','status','is_vip','is_auth','remember_token','ycode','latitude','longitude','online','notice_status','like_num','like_me_num','look_num','lock_pass','is_distory','registrationId','phoneModel'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    public function getJWTIdentifier()
    {
        return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
    }

    public function getJWTCustomClaims()
    {
        return [
            'role' => 'user'
        ];  // TODO: Implement getJWTCustomClaims() method.
    }

    /**
     * 设置密码加密
     * @param $value
     * @return string
     */
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = bcrypt($value);
    }

    public function user_info()
    {
        return $this->belongsTo(UserInfoModel::class,'id','user_id');
    }
}
