title: Mapping data in Laravel to a JSON object
body: <p>I'm trying to convert data retrieved from my Laravel model to a JSON object as outlined in the <a href="http://backbonejs.org/#FAQ-bootstrap" rel="nofollow">Backbone docs</a>.</p>
  
  <p>My problem is that when I encode the data all I get are the public properties and none of the (protected) attributes - the ones I actually want. This is how I go about it:</p>
  
  <p><em><strong>Controller</em></strong></p>
  
  <pre><code>$movie = Movie::with('awards.award', 'customAwards.awardCustom', 'cast.person', 'imdb.rottenTomatoes')-&gt;find($id);
  
  return View::make('movie')-&gt;with(array(
      'movie'     =&gt; $movie
  )); 
  </code></pre>
  
  <p><em><strong>View</em></strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      DS.Resources.Movie = {{json_encode($movie)}};
  &lt;/script&gt;
  </code></pre>
  
  <p><em><strong>DS.Resources.Movie output</em></strong></p>
  
  <pre><code>{
      "timestamps":false,
      "incrementing":true,
      "exists":true
  }
  </code></pre>
  
  <p>If I <code>var_dump</code> <code>$movie</code> I can see the protected attributes like title, year, a cast collection, awards collection etc. How do I access these properties and map them to my JSON object?</p>