Element API + checkboxes Using the Element API, I want to return the values from checkboxes (the $block->product field). These checkboxes are within a matrix that I am already gathering data from. Currently am doing this:



return [
'endpoints' =&gt; [
    'fullmembers.json' =&gt; [
        'elementType' =&gt; 'User',
        'criteria' =&gt; ['group' =&gt; 'fullMembership'],
        'transformer' =&gt; function(UserModel $member) {
            $businessCategories = [];
            foreach ($member-&gt;businessTypeMarketSectorsProducts as $block) {
                switch ($block-&gt;type-&gt;handle) {
                    case 'businessCategory':

                        $businessCategories[] = [
                            'businessType' =&gt; $block-&gt;businessType-&gt;value,
                            'marketSector' =&gt; $block-&gt;marketSector-&gt;value,
                            'product' =&gt; $block-&gt;product //Here you can see I'm calling the product field... 
                        ];
                        break;
                }
            }

            return [
                'id' =&gt; $member-&gt;id,
                'companyName' =&gt; $member-&gt;membersCompanyName,
                'addressLine3' =&gt; $member-&gt;membersAddressLine3,
                'lat' =&gt; $member-&gt;memberAddress-&gt;lat,
                'lng' =&gt; $member-&gt;memberAddress-&gt;lng,
                'email' =&gt; $member-&gt;email,
                // 'profile' =&gt; '/directory/company/' . $member-&gt;id . '/' . $member-&gt;username,
                'profile' =&gt; UrlHelper::getUrl("directory/company/{$member-&gt;id}"),
                'businessCategories' =&gt; $businessCategories
            ];
        },
    ]
]
];


Here is a sample response:

    {
  "id": "1506",
  "companyName": "Airsprung Group Plc",
  "addressLine3": "",
  "lat": "51.33188454",
  "lng": "-2.20657303",
  "email": "email@email.co.uk",
  "profile": "http:\/\/craft.fira\/directory\/company\/1506",
  "businessCategories": [{
    "businessType": "Manufacture",
    "marketSector": "Domestic",
    "product": {
      "0": {
        "label": "Beds",
        "value": "Beds",
        "selected": true
      },
      "1": {
        "label": "Mattresses",
        "value": "Mattresses",
        "selected": true
      },
      "2": {
        "label": "Seating \/ upholstery",
        "value": "Seating \/ upholstery",
        "selected": true
      }
    }
  }, {
    "businessType": "Manufacture",
    "marketSector": "Contract",
    "product": {
      "0": {
        "label": "Beds",
        "value": "Beds",
        "selected": true
      },
      "1": {
        "label": "Mattresses",
        "value": "Mattresses",
        "selected": true
      },
      "2": {
        "label": "Seating \/ upholstery",
        "value": "Seating \/ upholstery",
        "selected": true
      }
    }
  }]
}


I would like the response to just show the values of the product checkboxes. Can you suggest a way to do this so that I am not returning the label and selected states? Ideally something like this:

"product": {"Beds", "Mattresses", "Seating \/ upholstery"}
You should be able to foreach the $block->product to include the selected values (or labels)

return [
    'endpoints' =&gt; [
        'fullmembers.json' =&gt; [
            'elementType' =&gt; 'User',
            'criteria' =&gt; ['group' =&gt; 'fullMembership'],
            'transformer' =&gt; function(UserModel $member) {
                $businessCategories = [];
                foreach ($member-&gt;businessTypeMarketSectorsProducts as $block) {
                    switch ($block-&gt;type-&gt;handle) {
                        case 'businessCategory':
                            $productValues = [];
                            foreach ($block-&gt;product as $product) {
                                if ($product-&gt;selected) {
                                    $productValues[] = $product-&gt;value;
                                }
                            }
                            $businessCategories[] = [
                                'businessType' =&gt; $block-&gt;businessType-&gt;value,
                                'marketSector' =&gt; $block-&gt;marketSector-&gt;value,
                                'product' =&gt; $productValues
                            ];
                            break;
                    }
                }

                return [
                    'id' =&gt; $member-&gt;id,
                    'companyName' =&gt; $member-&gt;membersCompanyName,
                    'addressLine3' =&gt; $member-&gt;membersAddressLine3,
                    'lat' =&gt; $member-&gt;memberAddress-&gt;lat,
                    'lng' =&gt; $member-&gt;memberAddress-&gt;lng,
                    'email' =&gt; $member-&gt;email,
                    // 'profile' =&gt; '/directory/company/' . $member-&gt;id . '/' . $member-&gt;username,
                    'profile' =&gt; UrlHelper::getUrl("directory/company/{$member-&gt;id}"),
                    'businessCategories' =&gt; $businessCategories
                ];
            },
        ]
    ]
];