PostRecordModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 笔记动态/点赞或评论记录-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class PostRecordModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'posts_records';
  22. protected $appends = ['time_text'];
  23. public function getAlbumsAttribute($value)
  24. {
  25. return $value? get_images_preview($value,'url',2) : [];
  26. }
  27. public function getTimeTextAttribute()
  28. {
  29. return $this->create_time? dateFormat($this->create_time,'Y-m-d') : '';
  30. }
  31. /**
  32. * 发布用户
  33. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  34. */
  35. public function user()
  36. {
  37. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  38. ->select(['id','openid', 'mobile', 'nickname','avatar','balance', 'realname', 'status']);
  39. }
  40. /**
  41. * 回复用户
  42. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  43. */
  44. public function replyUser()
  45. {
  46. return $this->hasOne(MemberModel::class, 'id', 'reply_uid')
  47. ->select(['id','openid', 'mobile', 'nickname','avatar','balance', 'realname', 'status']);
  48. }
  49. /**
  50. * 笔记
  51. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  52. */
  53. public function posts()
  54. {
  55. return $this->hasOne(PostModel::class, 'id', 'source_id')
  56. ->select(['id','title', 'thumb', 'type','user_id', 'tags','status']);
  57. }
  58. /**
  59. * 回复
  60. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  61. */
  62. public function reply()
  63. {
  64. return $this->hasOne(PostRecordModel::class, 'id','reply_id');
  65. }
  66. /**
  67. * 回复
  68. * @return \Illuminate\Database\Eloquent\Relations\hasMany
  69. */
  70. public function replys()
  71. {
  72. return $this->hasMany(PostRecordModel::class, 'reply_id', 'id')->with(['user','replyUser']);
  73. }
  74. }