Article.php 1.2 KB

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