title: Unable to sort records according to price laravel
body: <p>I'm trying to sort the db records(tours) according to price (lowest to highest, highest to lowest). And I've added 12 dummy records in db with prices (100 to 1200) in series respectively. Below is my code in controller for performing the sort query:</p>
  
  <pre><code>    public function short(Request $request)
  {
      if ($request-&gt;sortby == "lower") {
          $query = Tour::query()-&gt;orderBy('price', 'asc');
          if (!empty($request-&gt;country)) {
              $query = $query-&gt;whereHas('country', function($r) use($request) {
                  $r-&gt;where('countries.name', $request-&gt;country);
              });
          }            
  
          if (!empty($request-&gt;category)) {
              $query = $query-&gt;whereHas('category', function($s) use($request) {
                  $s-&gt;where('categories.name', $request-&gt;category);
              });
          }
  
          if ($request-&gt;days !== null) {
              $days = $request-&gt;days;
              $days_explode = explode('|', $days);
              $query = $query-&gt;whereBetween('days', [$days_explode[0], $days_explode[1]]);                    
          }
          $query = $query-&gt;get();   
      }
      else{
          $query = Tour::query()-&gt;orderBy('price', 'desc');            
          if (!empty($request-&gt;country)) {
              $query = $query-&gt;whereHas('country', function($r) use($request) {
                  $r-&gt;where('countries.name', $request-&gt;country);
              });
          }            
  
          if (!empty($request-&gt;category)) {
              $query = $query-&gt;whereHas('category', function($s) use($request) {
                  $s-&gt;where('categories.name', $request-&gt;category);
              });
          }
  
          if ($request-&gt;days !== null) {
              $days = $request-&gt;days;
              $days_explode = explode('|', $days);
              $query = $query-&gt;whereBetween('days', [$days_explode[0], $days_explode[1]]);                    
          }
          $query = $query-&gt;get();               
      }
  
      return view('public.tour.search')-&gt;withResults($query);
  }  
  </code></pre>
  
  <p>When sort by lowest to highest is selected, records are displayed in the following order according to price price column of db table:</p>
  
  <p><code>100,1000,1100,1200,200,300,400,500,600,700,800,900</code></p>
  
  <p>and when highest to lowest is selected records are displayed in the following order according to price price column of db table:</p>
  
  <p><code>900,800,700,600,500,400,300,200,1200,1100,1000,100</code></p>
  
  <p>Can anyone help me please ?</p>