status == 1 ? ' Active ' : 'Inactive';
}
protected function createdBy(): Attribute
{
return Attribute::make(
get: fn ($value) => User::find($value) ? User::find($value)->name : '',
);
}
protected function updatedBy(): Attribute
{
return Attribute::make(
get: fn ($value) => User::find($value) ? User::find($value)->name : '',
);
}
public function parent()
{
return $this->belongsTo(News::class, 'parent_news');
}
public function children()
{
return $this->hasMany(News::class, 'parent_news');
}
public function newsType(): BelongsTo
{
return $this->belongsTo(News_Type::class, 'news_type_id', 'news_type_id');
}
public function newsCategories(): BelongsTo
{
return $this->belongsTo(Newscategories::class, 'newscategories_id', 'category_id');
}
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'authors_id', 'author_id');
}
public function provinces(): BelongsTo{
return $this->belongsTo(Provinces::class, 'provinces_id', 'province_id');
}
public function comments()
{
return $this->hasMany(Comments::class, 'news_id', 'news_id')->with('subcomments')
->where('parent_id', 0)
->orWhere('parent_id', null)
->where('status', 1);
}
}