title: Laravel 4 - how to return all validation error messages for all fields as a JSON structure?
body: <p>I'm upgrading from Laravel 3 to Laravel 4. My app has some AJAX-only forms that are rendered client-side (i.e. there are no server-side views). Therefore, instead of passing validation errors to views with the <strong>withErrors()</strong> method, I've been returning the validation error objects to the client as JSON structures.  </p>
  
  <p>In Laravel 3, I had this:</p>
  
  <pre><code>$validation = Validator::make(Input::all(), $rules);
  if($validation-&gt;fails())
  {
    return json_encode($validation-&gt;errors);
  }
  //else handle task
  </code></pre>
  
  <p>But in Laravel 4, the error messages are protected:</p>
  
  <pre><code>$validation = Validator::make(Input::all(), $rules);
  if($validation-&gt;fails())
  {
    var_dump($validation-&gt;messages());
    return json_encode($validation-&gt;messages());
  }
  //else handle task
  </code></pre>
  
  <p><strong>var_dump($validation->messages())</strong> returns:</p>
  
  <pre><code>object(Illuminate\Support\MessageBag)[333]
    protected 'messages' =&gt; 
      array (size=1)
        'delete_confirm_password' =&gt; 
          array (size=1)
            0 =&gt; string 'The delete confirm password field is required.' (length=46)
    protected 'format' =&gt; string ':message' (length=8)
  </code></pre>
  
  <p><strong>json_encode($validation->messages)</strong> returns</p>
  
  <pre><code>{}
  </code></pre>
  
  <p><strong>Question:</strong> how do I return all the validation error messages for all fields as a JSON structure in Laravel 4?</p>