Aronaman
1 month ago
222
3
Laravel

how can i shorten this code

Posted 1 month ago by Aronaman

it is working, but the only change is the start, end price value, how can I shorten this code without using merge

 $exchangeRateToDollar=Currency::where('currencyType','ETB')->firstOrFail()->exchangeRate;
 $startPriceDollar =$request->start_price*$exchangeRateToDollar;
 $endPriceDollar =$request->end_price*$exchangeRateToDollar;

 $organizationBirr= Organization::withCount(['rooms','confrences'])
        ->with(['typeOfOrganization','user'])->where('approved',1)
        ->when(request(['start_price','end_price']), function($query){
              return $query->where('organizations.avg_price','>=', request('start_price'))
                           ->where('organizations.avg_price','<=',request('end_price'));
            })})->get();


$organizationDollar=Organization::withCount(['rooms','confrences'])
            ->with(['typeOfOrganization','user'])->where('approved',1)
	    ->when(request(['start_price','end_price']), function($query) use ($startPriceDollar,$endPriceDollar){
                  return $query->where('organizations.avg_price','>=', $startPriceDollar)
                               ->where('organizations.avg_price','<=',$endPriceDollar);
                })->get();


 $organizations=$organizationBirr->merge($organizationDollar)->paginate(21);

Please sign in or create an account to participate in this conversation.