Article.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Prettus\Repository\Contracts\Transformable;
  5. use Prettus\Repository\Traits\TransformableTrait;
  6. class Article extends Model implements Transformable
  7. {
  8. use TransformableTrait;
  9. protected $table = 'articles';
  10. //protected $fillable = [];
  11. protected $guarded = ['id'];
  12. /**
  13. * 文章标签
  14. *
  15. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  16. */
  17. public function articleTag()
  18. {
  19. return $this->hasMany('App\Models\ArticleTag', 'article_id', 'id');
  20. }
  21. public function getStatusAttribute($value)
  22. {
  23. return $value == 1 ? '私密' : '公开';
  24. }
  25. /**
  26. * article 与 tag 多对多关联
  27. *
  28. * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  29. */
  30. public function tag()
  31. {
  32. return $this->belongsToMany('App\Models\Tag','article_tags', 'article_id', 'tag_id');
  33. }
  34. /**
  35. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  36. */
  37. public function category()
  38. {
  39. return $this->belongsTo('App\Models\Category', 'cate_id');
  40. }
  41. /**
  42. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  43. */
  44. public function user()
  45. {
  46. return $this->belongsTo('App\Models\User', 'user_id');
  47. }
  48. }