Update Article.php

This commit is contained in:
2020-10-12 07:54:17 +05:00
parent f6ccf564ca
commit d180f2a885

View File

@@ -2,6 +2,7 @@
namespace App; namespace App;
use App\Models\Category;
use GoldSpecDigital\LaravelEloquentUUID\Database\Eloquent\Uuid; use GoldSpecDigital\LaravelEloquentUUID\Database\Eloquent\Uuid;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Source; use App\Source;
@@ -32,7 +33,7 @@ class Article extends Model
*/ */
protected $guarded = []; protected $guarded = [];
/** /**
* The attributes that should be mutated to dates. * The attributes that should be mutated to dates.
* *
* @var array * @var array
@@ -61,4 +62,15 @@ class Article extends Model
{ {
return $this->belongsToMany(Topic::class)->withTimestamps(); return $this->belongsToMany(Topic::class)->withTimestamps();
} }
public function category()
{
return $this->belongsTo(Category::class);
}
public function ScopeRecentArticles()
{
return $this->with('source', 'topics')
->latest("published_date");
}
} }