Вы можете использовать эту коллекцию возврата Eloquent. Так что работайте с коллекцией.
public function getCountAdverts(): array
{
$adverts = Advert::get(); //this will be collection of all Adverts(Illuminate\Support\Collection)
return [
Advert::STATUS_PUBLISHED => $this->getCount($adverts, Advert::STATUS_PUBLISHED),
Advert::STATUS_CLOSED => $this->getCount($adverts, Advert::STATUS_CLOSED),
Advert::STATUS_NOT_PUBLISHED => $this->getCount($adverts, Advert::STATUS_NOT_PUBLISHED),
Advert::STATUS_MODERATION => $this->getCount($adverts, Advert::STATUS_MODERATION),
];
}
private function getCount($adverts, string $status): int
{
return $adverts->where('status', $status)->count();
}