Laravel / Model / Table joining with sub query
Joining with sub query
-
STEP
$data = DB::table("items") ->select("items.*","items_count.price_group","items_count.quantity_group") ->join(DB::raw("(SELECT items_count.id_item, GROUP_CONCAT(items_count.price) as price_group, GROUP_CONCAT(items_count.quantity) as quantity_group FROM items_count GROUP BY items_count.id_item ) as items_count"),function($join){ $join->on("items_count.id_item","=","items.id"); }) ->groupBy("items.id") ->get(); print_r($data);