PortalPostModel.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-18
  6. * Time: 11:30
  7. */
  8. namespace api\js\model;
  9. use think\Model;
  10. class PortalPostModel extends Model
  11. {
  12. protected $type = [
  13. 'more' => 'array',
  14. ];
  15. // 开启自动写入时间戳字段
  16. protected $autoWriteTimestamp = true;
  17. /**
  18. * 关联 user表
  19. * @return \think\model\relation\BelongsTo
  20. */
  21. public function user()
  22. {
  23. return $this->belongsTo('UserModel', 'user_id')->setEagerlyType(1);
  24. }
  25. /**
  26. * 关联分类表
  27. * @return \think\model\relation\BelongsToMany
  28. */
  29. public function categories()
  30. {
  31. return $this->belongsToMany('PortalCategoryModel', 'portal_category_post', 'category_id', 'post_id');
  32. }
  33. /**
  34. * 关联标签表
  35. * @return \think\model\relation\BelongsToMany
  36. */
  37. public function tags()
  38. {
  39. return $this->belongsToMany('PortalTagModel', 'portal_tag_post', 'tag_id', 'post_id');
  40. }
  41. /**
  42. * post_content 自动转化
  43. * @param $value
  44. * @return string
  45. */
  46. public function getPostContentAttr($value)
  47. {
  48. return cmf_replace_content_file_url(htmlspecialchars_decode($value));
  49. }
  50. }