title: Laravel response status code set to 400 but browser reports 200
body: <p>I'm trying to return a 400 status code from Laravel. I've setup a simple test in my controller:</p>
  
  <pre><code>return Response::json(["Test", "Array"], 400);
  </code></pre>
  
  <p>And look at web inspector I get a 200 OK.</p>
  
  <p>If I dump the response:</p>
  
  <pre><code>object(Illuminate\Http\JsonResponse)#306 (8) {
    ["data":protected]=&gt;
    string(16) "["Test","Array"]"
    ["callback":protected]=&gt;
    NULL
    ["headers"]=&gt;
    object(Symfony\Component\HttpFoundation\ResponseHeaderBag)#315 (5) {
     ["computedCacheControl":protected]=&gt;
      array(1) {
        ["no-cache"]=&gt;
        bool(true)
      }
      ["cookies":protected]=&gt;
      array(0) {
      }
      ["headerNames":protected]=&gt;
      array(3) {
        ["cache-control"]=&gt;
        string(13) "Cache-Control"
        ["date"]=&gt;
        string(4) "Date"
        ["content-type"]=&gt;
        string(12) "Content-Type"
      }
      ["headers":protected]=&gt;
      array(3) {
        ["cache-control"]=&gt;
        array(1) {
          [0]=&gt;
          string(8) "no-cache"
        }
        ["date"]=&gt;
        array(1) {
          [0]=&gt;
          string(29) "Wed, 02 Apr 2014 20:03:14 GMT"
        }
        ["content-type"]=&gt;
        array(1) {
          [0]=&gt;
          string(16) "application/json"
        }
      }
      ["cacheControl":protected]=&gt;
      array(0) {
      }
    }
    ["content":protected]=&gt;
    string(16) "["Test","Array"]"
    ["version":protected]=&gt;
    string(3) "1.0"
    ["statusCode":protected]=&gt;
    int(400)
    ["statusText":protected]=&gt;
    string(11) "Bad Request"
    ["charset":protected]=&gt;
    NULL
  }
  </code></pre>
  
  <p>I can see that the status code is set to 400 and the statusText is Bad Request.</p>
  
  <p>Basically I'm using Backbone.js in conjunction with Laravel and need to return a status code other than 200 to catch errors on save.</p>
  
  <p>This seems like such a simple thing to do, does anyone know what I'm having this issue?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After some head bashing I've found a (not very ideal) work around to achieve what I need, and logged a issue on the Laravel GitHub: <a href="https://github.com/laravel/laravel/issues/2796" rel="nofollow">https://github.com/laravel/laravel/issues/2796</a></p>
  
  <p>Basically I took my controller out of the equation and tried this as a route:</p>
  
  <pre><code>Route::get('/bad-request', function() {
      $response['state'] = "error";
      $response['errors'] = ["name" =&gt; ["A product name is required"]];
  
      return Response::json($response, 400);
  });
  </code></pre>
  
  <p>Same issue, returns a 200. Found this work around for the time being:</p>
  
  <pre><code>Route::get('/bad-request', function() {
      $response['state'] = "error";
      $response['errors'] = ["name" =&gt; ["A product name is required"]];
  
      http_response_code(400);
      return Response::json($response, 400);
  });
  </code></pre>
  
  <p>I'd much rather do this with Laravel than forcing it with PHP. Also I've tried <code>Response::make</code> and that does exactly the same thing.</p>