title: Laravel eloquent query 20 latest records in after an id?
body: <p>I have an id of a record. I need to query 20 latest records updated before the record with the id.</p>
  
  <p>Something like this</p>
  
  <pre><code>$orders = Order::latest('updated_at')-&gt;take(20)-&gt;before(id)-&gt;get();
  </code></pre>
  
  <p>I am using laravel5.5</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Looking at the answer I feel my question is not clear enough.</p>
  
  <p>Say this is my db table and id i have is 5</p>
  
  <pre><code>---------------------------------
  |id| name | updated_at          |
  |--|------|---------------------|
  |1 |a     | 2017-09-21 06:27:59 |
  |2 |b     | 2017-09-19 06:20:29 |
  |3 |c     | 2017-09-12 05:27:59 |
  |4 |d     | 2017-09-18 05:17:39 |
  |5 |e     | 2017-09-17 06:27:48 |
  |6 |b     | 2017-09-19 06:27:59 |
  |7 |f     | 2017-09-04 06:27:58 |
  |8 |g     | 2017-09-06 06:27:14 |
  </code></pre>
  
  <p>I want most recent updated records so</p>
  
  <pre><code>---------------------------------
  |id| name | updated_at          |
  |--|------|---------------------|
  |1 |a     | 2017-09-21 06:27:59 |
  |2 |b     | 2017-09-19 06:20:29 |
  |4 |d     | 2017-09-18 05:17:39 |
  |5 |e     | 2017-09-17 06:27:48 |
  |3 |c     | 2017-09-12 05:27:59 |
  |6 |b     | 2017-09-09 06:27:59 |
  |8 |g     | 2017-09-06 06:27:14 |
  |7 |f     | 2017-09-04 06:27:58 |
  </code></pre>
  
  <p>Now 20(in this case all) records updated before record with id 5</p>
  
  <pre><code>---------------------------------
  |id| name | updated_at          |
  |--|------|---------------------|
  |3 |c     | 2017-09-12 05:27:59 |
  |6 |b     | 2017-09-09 06:27:59 |
  |8 |g     | 2017-09-06 06:27:14 |
  |7 |f     | 2017-09-04 06:27:58 |
  </code></pre>
  
  <p>This is the result i need.</p>