title: Laravel - How to set HTTP response status code from Controller
body: <p>I'm new to laravel and am successfully directing users tothe appropriate views from a controller, but in some instances I want to set an http status code, but it is always returning a response code of <code>200</code> no matter what I send.</p>
  
  <p>Here is the code for my test controller function:</p>
  
  <pre><code>public function index()
  {
      $data=array();
  
      return response()-&gt;view('layouts.default', $data, 201);
  }
  </code></pre>
  
  <p>If I use the same code within a route, it will return the correct http status code as I see when I call the page with curl -I from the command line.</p>
  
  <pre><code>curl -I http://localhost/
  </code></pre>
  
  <p>Is there a reason why it doesn't work within a controller, but does within a route call?</p>
  
  <p>I'm sure there is something I'm just misunderstanding as a newbie, but even the following code works in a route but not a controller:</p>
  
  <pre><code>public function index()
  {
      abort(404);
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>