public function getActiveCommentsAttribute()
{
return $this->comments->where('pivot.status', 1);
}
public function getInactiveCommentsAttribute()
{
return $this->comments->where('pivot.status', 0);
}
@forelse ($post->inactive_comments as $comment)
...
@endfoelse
class Post {
// comments() relation goes here
public function getActiveCommentsAttribute()
{
return $this->comments->where('status', 1);
}
public function getInactiveCommentsAttribute()
{
return $this->comments->where('status', 0);
}
}
$post = Post::with(['comments'])->first();
$post->active_comments;
$post->inactive_comments;