title: How to get nearest row in Laravel?
body: <p>I have a table with price column. Now I want to get the nearest row by price.
  Like: If I give value 1000 need to return 3,5,6 no. row., if I give value 100 need to return 1,2 no. row</p>
  
  <p>Pack Table Demo</p>
  
  <pre><code>id - name - provider_id - price - others_field
  1  - name -    1        -  10
  2  - name -    1        -  120
  3  - name -    1        -  600
  4  - name -    1        -  320
  5  - name -    1        -  1000
  6  - name -    1        -  1020
  </code></pre>
  
  <p>I've tried with the following way by searching google. But it's not working properly.</p>
  
  <pre><code>$suggestions = new Pack; 
  $suggestions = $suggestions-&gt;where('status', 1);   
  $suggestions = $suggestions-&gt;where('provider_id', $request-&gt;provider_id);  
  $suggestions = $suggestions-&gt;select('*', DB::raw("ABS(price - $request-&gt;price) AS distance"))-&gt;orderBy('distance'); 
  
  $suggestions = $suggestions-&gt;take(3); 
  $suggestions = $suggestions-&gt;get();  
  
  $curent = '';
  $suggestion_lower = '';
  $suggestion_higher = '';
  
  foreach ($suggestions as $value) {
      if ( $request-&gt;price == $value-&gt;price ) {
          $curent = $value;
      }
  
      if ( $request-&gt;price &gt; $value-&gt;price ) {
          $suggestion_lower = $value;
      }
  
      if ( $request-&gt;price &lt; $value-&gt;price ) {
          $suggestion_higher = $value;
      }
  }
  
  $suggestions = [
      'curent' =&gt; $curent,
      'suggestion_higher' =&gt; $suggestion_higher,
      'suggestion_lower' =&gt; $suggestion_lower,
  ];
  </code></pre>