UserInfoModel.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Models;
  3. use App\Models\BaseModel;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Laravel\Passport\HasApiTokens;
  6. use Illuminate\Notifications\Notifiable;
  7. /**
  8. * @description 用户表
  9. * @author system;
  10. * @version 1.0
  11. * @date 2017-05-30 12:16:56
  12. *
  13. */
  14. class UserInfoModel extends Authenticatable
  15. {
  16. use HasApiTokens, Notifiable;
  17. /**
  18. * 数据表名
  19. *
  20. * @var string
  21. *
  22. */
  23. protected $table = 'user_info';
  24. /**
  25. 主键
  26. */
  27. protected $primaryKey = 'id';
  28. //分页
  29. protected $perPage = PAGE_NUMS;
  30. /**
  31. * 可以被集体附值的表的字段
  32. *
  33. * @var string
  34. */
  35. protected $fillable = [
  36. 'phone',
  37. 'password',
  38. 'nickname',
  39. 'sign',
  40. 'avatar',
  41. 'money',
  42. 'coin',
  43. 'sex',
  44. 'city',
  45. 'signture',
  46. 'height',
  47. 'work',
  48. 'emotion',
  49. 'address',
  50. 'detail_address',
  51. 'status',
  52. 'remember_token',
  53. ];
  54. protected $hidden = ['password'];
  55. public function UserCareUser()
  56. {
  57. return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
  58. }
  59. public function UserCareDream()
  60. {
  61. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');
  62. }
  63. // 系统消息
  64. public function systemInfo()
  65. {
  66. return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
  67. }
  68. //用户梦想
  69. public function dreams()
  70. {
  71. return $this->hasMany('App\Models\DreamInfoModel','user_id','id');
  72. }
  73. //支持的梦想
  74. public function supDream()
  75. {
  76. return $this->belongsToMany('App\Models\DreamInfoModel','support_dream','user_id','dream_id');
  77. }
  78. //评论的梦想
  79. public function comDream()
  80. {
  81. return $this->belongsToMany('App\Models\DreamInfoModel','comments_info','user_id','dream_id')->withPivot('content', 'level','created_at');
  82. }
  83. //收藏的梦想
  84. public function careDreams()
  85. {
  86. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id');
  87. }
  88. //关注我的用户
  89. public function fens()
  90. {
  91. return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
  92. }
  93. // 我的收藏
  94. public function collection()
  95. {
  96. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number','dream_user_id');
  97. }
  98. // 回复的梦想
  99. public function replyDream()
  100. {
  101. return $this->belongsToMany('App\Models\CommentInfoModel','reply_comments_info','user_id','comment_id')->withPivot('content', 'level','created_at');
  102. }
  103. // 搜索
  104. public function search()
  105. {
  106. return $this->hasMany('App\Models\SearchInfoModel','user_id','id');
  107. }
  108. // 获取所有梦想的图片
  109. public function allImgs()
  110. {
  111. return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
  112. }
  113. // 获取所有梦想的互动
  114. public function allInteraction()
  115. {
  116. return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
  117. }
  118. // 我的银行卡
  119. public function bank()
  120. {
  121. return $this->hasMany('App\Models\UserBank','user_id','id');
  122. }
  123. }