ArticleReply.php 704 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\models\article;
  3. use app\models\user\User;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. use think\model\relation\HasOne;
  7. /**
  8. * 文章详情
  9. * Class ArticleCategory
  10. * @package app\models\article
  11. */
  12. class ArticleReply extends BaseModel
  13. {
  14. use ModelTrait;
  15. public function user(): HasOne
  16. {
  17. return self::hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar');
  18. }
  19. public function article(): HasOne
  20. {
  21. return self::hasOne(Article::class, 'id', 'aid')->field('*');
  22. }
  23. // 统计文章评论数
  24. public function counts($id)
  25. {
  26. $model = new self();
  27. $counts=$model::where('aid',$id)->count();
  28. return $counts;
  29. }
  30. }