Element API: Get Matrix Content
In order to get all related items from a BaseRelationField you'll need this syntax

$entry-&gt;getFieldValue('contentMatrix')-&gt;all() 


Thus your loop will be

foreach($entry-&gt;getFieldValue('contentMatrix')-&gt;all() as $block){