mercredi 26 février 2020

Laravel DB::raw query using multiple WHERE clauses

So I have a query that I would want to add some extra conditions to.

Query:

$providers = BusinessDetail::select(
    'business_details.name as description', 
    DB::raw('SUM(review_details.param_value) / COUNT(review_headers.id) AS avgUserReview')
)
->leftJoin('review_headers', 'business_details.id', '=', 'review_headers.business_detail_id')
->leftJoin('review_details', 'review_headers.id', '=', 'review_details.review_header_id')
->leftJoin('rate_params', 'review_details.rate_param_id', '=', 'rate_params.id')
->get();

I would want to add the following to the query DB::raw query DB::raw('SUM(review_details.param_value) / COUNT(review_headers.id) AS avgUserReview') alone.

->whereIn('rate_params.id', [1, 3, 4, 5])
->where('review_details.param_value', '<>', NULL)
->where('review_details.param_value', '<>', '')
->where('review_headers.review_status', '=', 1)

How do I go about that?

Anyone?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire