ArticleModel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 ArticleModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'article';
  22. protected $appends = ['time_text'];
  23. // 封面图
  24. public function getCoverAttribute($value)
  25. {
  26. $value = $value ? get_image_url($value) : '';
  27. return $value;
  28. }
  29. public function setCoverAttribute($value)
  30. {
  31. return $value ? get_image_path($value) : '';
  32. }
  33. // 时间
  34. public function getTimeTextAttribute()
  35. {
  36. return $this->create_time ? format_time(strtotime($this->create_time)) : '';
  37. }
  38. /**
  39. * 分类
  40. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  41. */
  42. public function category()
  43. {
  44. return $this->hasOne(ArticleCateModel::class, 'id', 'cate_id')
  45. ->select(['id', 'name', 'type']);
  46. }
  47. }