Chart retunrs first record only... why?

Hi, I'm implementing a chart widget on which I want to display the usage of tags.

Models:
CommentTag
Comment

Relationship:
Many to many

Pivot table:
comment_comment_tag

The following shows only the first record.

protected function getData(): array
    {
        $commentTags = CommentTag::with('comments')->get();

        $commentTags->loadCount('comments');

        foreach ($commentTags as $commentTag) {
            return [
                'datasets' => [
                    [
                        'label' => 'Commnets Tags Usage',
                        'data' => [$commentTag->comments_count],
                    ],
                ],
                'labels' => [$commentTag->name],
            ];
        }
    }

Any advice, thank you.
Was this page helpful?