Answers.Body: <p>Yes - you can access it exactly the same way you do in the templates; you just need to use PHP syntax (e.g. <code>-&gt;</code> for accessing sub-properties rather than <code>.</code>).</p>
  
  <pre class="lang-php prettyprint-override"><code>'transformer' =&gt; function(EntryModel $entry) {
      // Begin defining the response data for this entry
      $data = [
          'excerpt' =&gt; $entry-&gt;excerpt,
      ];
  
      // Get the first asset in a "heroImage" Assets field (if there is one)
      $heroImage = $entry-&gt;heroImage-&gt;first();
  
      if ($heroImage) {
          $data['heroImage'] = $heroImage-&gt;url;
      }
  
      return $data;
  })
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-14T22:19:52.153Z
Answers.Text: Hi Brandon, works a charm. Thanks, and thanks for the stellar software!
Answers.UserDisplayName: A Ron
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-14T21:26:58.743Z
Answers.LastActivityDate: 2016-01-14T21:26:58.743Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm using the Element API plugin to return data from an entry that also contains an image asset. Is there a way to combine the two so I can get the asset URL alongside the entry fields? </p>
  
  <p>Attached below is an approximation of my line of thinking.</p>
  
  <pre><code>        'elementType' =&gt; 'Entry',
          'criteria' =&gt; ['section' =&gt; 'wax'],
  
          'transformer' =&gt; function(EntryModel $entry) {
              return [
                  'excerpt' =&gt; $entry-&gt;excerpt,
                  'heroImage' =&gt; $asset-&gt;heroImage.url // Something like this?
              ];
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-14T21:23:34.207Z
Comments.Text: So the asset field is a custom field on the entry?
Comments.UserDisplayName: Brad Bell
Tags: <elementcriteriamodel><plugin-elementapi>
Title: Is there a way to return asset data along with entry data?
ThreadText: # Is there a way to return asset data along with entry data?
  
  (Asked by: username_0 on 2016-01-14)
  
  I'm using the Element API plugin to return data from an entry that also contains an image asset. Is there a way to combine the two so I can get the asset URL alongside the entry fields?
  
  Attached below is an approximation of my line of thinking.
  
  ```
          'elementType' => 'Entry',
          'criteria' => ['section' => 'wax'],
  
          'transformer' => function(EntryModel $entry) {
              return [
                  'excerpt' => $entry->excerpt,
                  'heroImage' => $asset->heroImage.url // Something like this?
              ];
  
  ```
  
  **Tags:** elementcriteriamodel, plugin-elementapi
  
  > **Comments:**
  > **username_1**: So the asset field is a custom field on the entry?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-01-14. Score: 4
  
  Yes - you can access it exactly the same way you do in the templates; you just need to use PHP syntax (e.g. `->` for accessing sub-properties rather than `.`).
  
  ```php
  'transformer' => function(EntryModel $entry) {
      // Begin defining the response data for this entry
      $data = [
          'excerpt' => $entry->excerpt,
      ];
  
      // Get the first asset in a "heroImage" Assets field (if there is one)
      $heroImage = $entry->heroImage->first();
  
      if ($heroImage) {
          $data['heroImage'] = $heroImage->url;
      }
  
      return $data;
  })
  
  ```
  
  > **Comments:**
  > **username_0**: Hi username_2, works a charm. Thanks, and thanks for the stellar software!  
  
  ---
  
  