title: Laravel - check if Ajax request
body: <p>I have been trying to find a way to determine Ajax calls in Laravel but I have not found any documentation about it.</p>
  <p>I have an <code>index()</code> controller function where I want to handle the response differently based on the nature of the request. Basically this is a resource controller method that is bound to GET request.</p>
  <pre class="lang-php prettyprint-override"><code>public function index()
  {
      if(!$this-&gt;isLogin())
          return Redirect::to('login');
              
      if(isAjax()) // This is what I am needing.
      {
          return $JSON;
      }
  
      $data = array(
          'records' =&gt; $this-&gt;table-&gt;fetchAll()
      );
  
      $this-&gt;setLayout(compact('data'));
  }
  </code></pre>
  <p>I know the other methods of determining the Ajax request in PHP but I want something specific to Laravel.</p>
  <p>Thanks</p>
  <p><strong>Updated:</strong></p>
  <p>I tried using</p>
  <pre class="lang-php prettyprint-override"><code>if(Request::ajax())
  {
      echo 'Ajax';
  }
  </code></pre>
  <p>But I am receiving this error:</p>
  <p><code>Non-static method Illuminate\Http\Request::ajax() should not be called statically, assuming $this from incompatible context</code></p>
  <p>The class shows that this is not a static method.</p>