Element API Fetch Entries URL Within Matrix I have a matrix with a field to set a Entries URL. Unfortunately the entry is not being returned, only an empty object. 

Here are my field settings below and element api code.  

See below for the response within the json. I get an empty object? 

Why is no data coming through? 



I'm fetching the data within a function like so: 





Here is the code from my Element API:

function panelsMatrix($array) {
    $panelBlocks = [];
    foreach ($array as $block) {
        switch ($block-&gt;type-&gt;handle) {
            case 'panel':
                $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; $block-&gt;subPageDirect-&gt;first()
                ];
            break;
        }
    }
    return $panelBlocks;
}
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;
}