Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Aronaman's avatar

conver to database query builder

any help, change a given eloquent query to database query

$exchangeRate = Currency::where('currencyType', 'USD')->firstOrFail()->exchangeRate;

// change $organizations to database query 
$organizations = Organization::withCount(['rooms','confrences'])->with(['typeOfOrganization','user'])
->where('approved', 1)->when(request('type_of_organization'), function($query){ return $query->where('organizations.type_of_organization_id', 	request('type_of_organization')); })

->when($request->has(['start_price', 'end_price']), function ($query) use ($request, $exchangeRate) {
    return $query->where(function ($query) use ($request) {
      $query->whereBetween('avg_price', [
      $request->start_price, $request->end_price
     ])->where('currency_id', 1);
      })->orWhere(function ($query) use ($request, $exchangeRate) {
        $query->whereBetween('avg_price', [
        $request->start_price * $exchangeRate, $request->end_price * $exchangeRate
      ])->where('currency_id', 2);
   });
 })->get();

thanks in advance

0 likes
7 replies
MichalOravec's avatar

You work only with one table, result will be almost the same.

Aronaman's avatar

3-4 sec is very slow? right how to cache js and css

Aronaman's avatar

@michaloravec thanks very much it help full the documentation.

I am not using laravel mix rather I minified manually and added it to the public directorate. for this case how to use cache

MichalOravec's avatar

What have common database query and laravel mix in this thread?

Please or to participate in this conversation.