Monday, March 13, 2017

how to convert sql query to eloquent laravel?

how to convert simple mysql query to eloquent laravel?

in fact iwanna convert down query :

 SELECT temp.* FROM
(SELECT * FROM avilableproducts ORDER BY avilableproducts.count DESC) AS temp
GROUP BY temp.products_id, temp.color
HAVING temp.products_id = 27
ORDER BY temp.count DESC;

to

        $Avilableproducts = $Avilableproducts->select(DB::raw('temp.*'))->from(
            DB::raw('(SELECT * FROM avilableproducts ORDER BY count DESC) AS temp')
        )->groupBy(['products_id','color'])->orderBy('count', 'desc');



via pichanakian

Advertisement