我有多个产品保存在mysql表中 . 它有2列:价格和货币 . 我想要的是:根据货币的价格范围和货币来订购产品 .

例如 .

ID-----PRICE---CURRENCY
1-------10-------USD
2-------8-------EURO
3-------43-------CHF

我有以下价格范围:10和18瑞士法郎 . 我想将它们中的每一个转换为CHF,然后对它们进行排序 . 我可以使用Laravel的查询构建器吗?我可以以某种方式将函数传递给laravel的where或orderby查询构建器或其他什么?

编辑:

我的 table 看起来像

ID(int)-----PRICE(int)---CURRENCY(string)-------OTHER COLLUMNS
1--------------10-----------'USD'--------------OTHER VALUES
2--------------8------------'EURO'--------------OTHER VALUES
3--------------43-----------'CHF'---------------OTHER VALUES

但现在这些都无关紧要 . 我目前的代码是:

/* Price form and to */
      if($filters->price_start != null && $filters->price_end!= null)
      {
        $query->where('price', '>=' , $filters->price_start)
        ->where('price', '<=', $filters->price_end);
      }
      else if($filters->price_start != null)
      {
        $query->where('price', '>=' , $filters->price_start);
      }
      else if($filters->price_end != null){
        $query->where('price', '<=', $filters->price_end);
      }

但它没有考虑货币因素 .

编辑2:

就像是

$query->where('price', '>=', $filters->price_start, function((e)
{ 
   if($this->currency != 'CHF') 
   $this->price = $this->price * rate[$this->currency];
});