title: Laravel, query to show big data is slow
body: <p>I have a page for user searching data from specific date range and it will show result in datatable e.g (<code>ID</code>, <code>Audit type</code>, <code>user</code>, <code>new value</code>, <code>old value</code> etc.) and it was from 2 table relationship.</p>
  <p>Here is my query:</p>
  <pre><code>$audits = \OwenIt\Auditing\Models\Audit::with('user')
      -&gt;orderBy('updated_at', 'DESC')
      -&gt;where('created_at', '&gt;=', $date1)
      -&gt;where('created_at', '&lt;=', $date2)
      -&gt;get;
  </code></pre>
  <p>The problem is if amount of data is big, the process so slow. How to optimize the query?</p>
  <p>I've tried to use <code>paginate(10)</code> or <code>take(10)</code>, but it only show 10 data not all data.</p>