Level 2
Try this
$exchangeRateToDollar = Currency::where('currencyType','ETB')->firstOrFail()->exchangeRate;
$startPriceDollar = $request->start_price * $exchangeRateToDollar;
$endPriceDollar = $request->end_price * $exchangeRateToDollar;
$organizations = Organization::withCount(['rooms','confrences'])->with(['typeOfOrganization','user'])->where('approved', 1)->when(request(['start_price', 'end_price']), function($query) use ($startPriceDollar, $endPriceDollar) {
return $query->where(function($q) {
return $q->where('organizations.avg_price', '>=', request('start_price'))->where('organizations.avg_price', '<=', request('end_price'));
})->orWhere(function($q) {
return $q->where('organizations.avg_price', '>=', $startPriceDollar)->where('organizations.avg_price', '<=', $endPriceDollar);
});
})->get();
$organizations = $organizations->paginate(21);
1 like