UserInfoModel.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. 'sex',
  43. 'city',
  44. 'signture',
  45. 'height',
  46. 'work',
  47. 'emotion',
  48. 'address',
  49. 'detail_address',
  50. 'status',
  51. 'remember_token',
  52. ];
  53. protected $hidden = ['password'];
  54. public function UserCareUser()
  55. {
  56. return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id')->withPivot('dream_num');
  57. }
  58. public function UserCareDream()
  59. {
  60. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');
  61. }
  62. // 系统消息
  63. public function systemInfo()
  64. {
  65. return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
  66. }
  67. //用户梦想
  68. public function UserDream()
  69. {
  70. return $this->hasMany('App\Models\DreamInfoModel','user_id','id');
  71. }
  72. //支持的梦想
  73. public function supDream()
  74. {
  75. return $this->belongsToMany('App\Models\DreamInfoModel','support_dream','user_id','dream_id');
  76. }
  77. //评论的梦想
  78. public function comDream()
  79. {
  80. return $this->belongsToMany('App\Models\DreamInfoModel','comments_info','user_id','dream_id')->withPivot('content', 'level','created_at');
  81. }
  82. //关注的用户
  83. public function myCareNum()
  84. {
  85. return $this->hasMany('App\Models\UserCareUser','user_id','id');
  86. }
  87. //关注我的用户
  88. public function myFans()
  89. {
  90. return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
  91. }
  92. // 我的收藏
  93. public function myCollection()
  94. {
  95. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id');
  96. }
  97. // 回复的梦想
  98. public function replyDream()
  99. {
  100. return $this->belongsToMany('App\Models\CommentInfoModel','reply_comments_info','user_id','comment_id')->withPivot('content', 'level','created_at');
  101. }
  102. // 搜索
  103. public function search()
  104. {
  105. return $this->hasMany('App\Models\SearchInfoModel','user_id','id');
  106. }
  107. // 获取所有梦想的图片
  108. public function allImgs()
  109. {
  110. return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
  111. }
  112. // 获取所有梦想的互动
  113. public function allInteraction()
  114. {
  115. return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
  116. }
  117. }