<?php
namespace App\Models;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
class Article extends Model implements Transformable
{
use TransformableTrait;
protected $fillable = [];
public function categories()
{
return $this->belongsToMany('App\Models\ArticleCategory', 'article_cate')->using('App\Models\ArticleCate');
}
public function tags()
{
return $this->belongsToMany('App\Models\ArticleTag', 'article_tag');
}
public function hasCategory($category_id)
{
$result = $this->categories()->where('article_category_id', $category_id)->first();
if (empty($result)) {
return false;
}
return true;
}
public function hasTag($tag_id)
{
$result = $this->tags()->where('article_tag_id', $tag_id)->first();
if (empty($result)) {
return false;
}
return true;
}
}