Rahul Vp Rahul Vp - 1 year ago 66
MySQL Question

How to write normal sql query into laravel 5.2 format

How to write my sql query in laravel 5.2, query is giving below

SELECT a.groupID, count( * ) AS totalCount, b.description
FROM devicelist AS a, devicegroup AS b
WHERE a.groupID = b.groupID
GROUP BY a.groupID

Answer Source


$query = DB::table('devicelist as a')
  ->join('devicegroup as b', 'a.groupID', '=', 'b.groupID')
  ->select(DB::raw('count(*) as user_count, a.groupID, b.description'))