title: Converting Laravel-4 Eloquent query results to arrays
body: <p>I'm trying to get my route to insert a new row into the database, and if successful return the record (with its new primary key id) in some JSON. I'm getting the following error:</p>
  
  <pre><code>{
      "error":
      {
          "type":"BadMethodCallException",
          "message":"Call to undefined method Illuminate\\Database\\Query\\Builder::to_array()",
          "file":"\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Query\\Builder.php",
          "line":1418
      }
  
  }
  </code></pre>
  
  <p>This is my route:</p>
  
  <pre><code>Route::post('/client/create', function()
  {
      $client = Client::create(Input::all());
      if($client)
      {
          return json_encode(array('Result' =&gt; 'OK', 'Record' =&gt; $client-&gt;to_array()));
      }
      else
      {
          return json_encode(array('Result' =&gt; 'ERROR', 'Message' =&gt; 'Error Inserting Record =('));
      }
  });
  </code></pre>
  
  <p>According to the Laravel docs I've read, you're supposed to use <code>-&gt;to_array()</code> to convert your model to an array, and <code>::create</code> returns an instance of the model if successfully inserted. I've checked the database, and the records are being inserted just fine.</p>