File: /var/www/hobbyistgarage/app/Models/Article.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasFactory;
protected $fillable = [
'title', 'description','short_url','banner_url', 'article','tags','video', 'editor_pick', 'published',
];
public function author()
{
return $this->belongsTo('App\Models\Author', 'author_id');
}
public function comments()
{
return $this->hasMany('App\Models\Comment', 'article_id');
}
public function categories()
{
return $this->hasManyThrough('App\Models\Category', 'App\Models\CategoryArticle', 'article_id', 'id', 'id' ,'category_id');
}
public function tags()
{
return $this->hasManyThrough('App\Models\Tag', 'App\Models\ArticleTag', 'article_id', 'id', 'id' ,'tag_id');
}
}