Element API Fetch Entries URL Within Matrix
That's because you don't actually fetch the entry. In order to receive the entry you have to execute your ElementCriteriaModel with first() or find() otherwise Craft tries to json encode a query

 $block-&gt;subPageDirect-&gt;first()


You should read the docs about relations and the Element Criteria Model 

Btw stack exchange has a wonderful syntax highlighting please add your code directly the next time and not in a screenshot

Edit:

function panelsMatrix($array) {
    $panelBlocks = [];
    foreach ($array as $block) {
        switch ($block-&gt;type-&gt;handle) {
            case 'panel':
                $relatedEntries =  $block-&gt;subPageDirect-&gt;first();
                $attributes = $relatedEntries? $relatedEntries-&gt;getAttributes() : [];

                $panelBlocks[] = [
                    'heading' =&gt; (string) $block-&gt;heading,
                    'text' =&gt; (string) $block-&gt;text,
                    'image' =&gt; $block-&gt;image[0]-&gt;url,
                    'imagePosition' =&gt; $block-&gt;imagePosition,
                    'textBaseColour' =&gt; $block-&gt;textBaseColour,
                    'textHorizontalAlignment' =&gt; $block-&gt;textHorizontalAlignment,
                    'textVerticalAlignment' =&gt; $block-&gt;textVerticalAlignment,
                    'imageOffsetX' =&gt;$block-&gt;imageOffsetX,
                    'imageOffsetY' =&gt;$block-&gt;imageOffsetY,
                    'backgroundColour' =&gt; $block-&gt;backgroundColour,
                    'subPageDirect' =&gt; $attributes
                ];
            break;
        }
    }
    return $panelBlocks;
}