userGroup->currencyExchangeRates() ->where(function (Builder $q) use ($from, $to) { $q->where('from_currency_id', $from->id) ->orWhere('to_currency_id', $to->id); }) ->orWhere(function (Builder $q) use ($from, $to) { $q->where('from_currency_id', $to->id) ->orWhere('to_currency_id', $from->id); }) ->orderBy('date', 'DESC')->get(); } }