lundi 26 décembre 2016

How to select count and use where with Laravel's fluent query builder?

in my case

$products = $products->select(array('products.*', \DB::raw('COUNT(extra_fields.price) as price_count')))->leftJoin('extra_fields', 'products.id', '=', 'extra_fields.item_id')
                    ->where('item_type', 'App\Models\Product')
                    ->whereRaw("price = '0'")
                    ->whereRaw("price_count = 1")
                    ->groupBy('item_id')
                    ->groupBy('price')

                ;

when i want to use { price_count } in where or whereRaw i got :

Column not found: 1054 Unknown column 'price_count'

price_count just only work on this way :

->orderBy('price_count')

how can i use price_count on where or whereRaw ?

any advice ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire