| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- class Article extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'articles';
- //protected $fillable = [];
- protected $guarded = ['id'];
- /**
- * 文章标签
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function articleTag()
- {
- return $this->hasMany('App\Models\ArticleTag', 'article_id', 'id');
- }
- public function getStatusAttribute($value)
- {
- return $value == 1 ? '私密' : '公开';
- }
- /**
- * article 与 tag 多对多关联
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
- */
- public function tag()
- {
- return $this->belongsToMany('App\Models\Tag','article_tags', 'article_id', 'tag_id');
- }
- /**
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function category()
- {
- return $this->hasOne('App\Models\Category', 'id', 'cate_id');
- }
- /**
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function user()
- {
- return $this->hasOne('App\Models\User', 'id', 'user_id');
- }
- }
|