Matrix | Craft 3 Element API / Scout Plugin I am trying to grab the contents a matrix field (Redactor).

Here is the section of code I am struggling with:

$bodyBlocks = [];
foreach ($entry-&gt;getFieldValue('pageBuilder')-&gt;all() as $block){
   switch ($block-&gt;type-&gt;handle) {
      case 'blockText':
      $bodyBlocks = $block-&gt;blockTextPara;
      break;
   }
}

// Begin defining the response data for this entry
$data = [
  'title' =&gt; $entry-&gt;title,
  'slug' =&gt; $entry-&gt;url,
  'status' =&gt; $entry-&gt;status,
  'textArea' =&gt; $bodyBlocks,
]; 


It is submitting to Algolia but the contents of the matrix block is empty. 

{
  "title": "Transport",
  "slug": "http://xxxxx/boarding-at-bruern/the-london-link",
  "status": "live",
  "textArea": {},
  "heroBanner": "http://xxxx/images/uploads/banners/_algoliaTransform/ASC7795.jpg",
  "objectID": "1_408"
}


For reference here is my entire scout.php config file:

&lt;?php

    return [
        "sync" =&gt; true,
        "application_id" =&gt; "xxx",
        "admin_api_key" =&gt; "xxx",
        "mappings" =&gt; [
            [
                'indexName' =&gt; 'xxx',
                'elementType' =&gt; \craft\elements\Entry::class,
                'criteria' =&gt; [
                    'section' =&gt; 'websitePages',
                    'type' =&gt; 'websitePages'
                ],            
                'transformer' =&gt; function(craft\elements\Entry $entry) {

                    Craft::$app-&gt;getConfig()-&gt;getGeneral()-&gt;generateTransformsBeforePageLoad = true;

                    $bodyBlocks = [];
                    foreach ($entry-&gt;getFieldValue('pageBuilder')-&gt;all() as $block){
                        switch ($block-&gt;type-&gt;handle) {
                            case 'blockText':
                                $bodyBlocks = $block-&gt;blockTextPara;
                                break;
                        }
                    }

                    // Begin defining the response data for this entry
                    $data = [
                        'title' =&gt; $entry-&gt;title,
                        'slug' =&gt; $entry-&gt;url,
                        'status' =&gt; $entry-&gt;status,
                        'textArea' =&gt; $bodyBlocks,
                    ];              

                    // Get the first asset in a "heroBanner" Assets field (if there is one) and then add it to the data array.         
                    $heroBanner = $entry-&gt;heroBanner-&gt;one();                
                    $data['heroBanner'] = $heroBanner ? $heroBanner-&gt;getUrl('algoliaTransform') : '/images/site/search-default.jpg';

                    return $data;               

                },
            ],
        ],
    ];
The first code section looks correct, other than that you're first creating a bodyBlocks array and then assigning a string to it, but that's not really consequential and not the issue behind this failing.

Do yourself a favor and set up PHPStorm + xdebug, you'll find the issue very easily. I suspect you might have some mixed up identifiers (field names, block handles) etc.