<?php
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
/**
 *  @description 用户表
 *  @author  system;
 *  @version    1.0
 *  @date 2017-05-30 12:16:56
 *
 */
class UserInfoModel extends Authenticatable
{
    use HasApiTokens, Notifiable;
    /**
     * 数据表名
     *
     * @var string
     *
     */
    protected $table = 'user_info';
    /**
    主键
     */
    protected $primaryKey = 'id';

    //分页
    protected $perPage = PAGE_NUMS;

    /**
     * 可以被集体附值的表的字段
     *
     * @var string
     */
    protected $fillable = [
                           'phone',
                           'password',
                           'nickname',
                           'sign',
                           'avatar',
                           'money',
                           'coin',
                            'sex',
                            'city',
                           'signture',
                           'height',
                           'work',
                           'emotion',
                           'address',
                           'detail_address',
                           'status',
                           'remember_token',
                          ];

    protected $hidden = ['password'];

    public function UserCareUser()
    {
        return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id')->withPivot('dream_num');
    }
    public function UserCareDream()
    {
        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');
    }



//    系统消息
    public function systemInfo()
    {
        return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
    }
//用户梦想
    public function dreams()
    {
        return $this->hasMany('App\Models\DreamInfoModel','user_id','id');
    }
//支持的梦想
    public function supDream()
    {
        return $this->belongsToMany('App\Models\DreamInfoModel','support_dream','user_id','dream_id');
    }
//评论的梦想
    public function comDream()
    {
        return $this->belongsToMany('App\Models\DreamInfoModel','comments_info','user_id','dream_id')->withPivot('content', 'level','created_at');
    }
//收藏的梦想
    public function careDreams()
    {
        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id');
    }
//关注我的用户
    public function fens()
    {
        return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
    }
//    我的收藏
    public function collection()
    {
        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number','dream_user_id');
    }
//    回复的梦想
    public function replyDream()
    {
        return $this->belongsToMany('App\Models\CommentInfoModel','reply_comments_info','user_id','comment_id')->withPivot('content', 'level','created_at');
    }

//    搜索
    public function search()
    {
        return $this->hasMany('App\Models\SearchInfoModel','user_id','id');
    }
//    获取所有梦想的图片
    public function allImgs()
    {
        return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
    }
    //    获取所有梦想的互动
    public function allInteraction()
    {
        return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
    }

}