left join countlaravel code example
Example 1: count with left join in laravel
$areas = Area::select('areas.*', DB::raw('count(area_id) as connections'))
->leftJoin('object_areas', 'object_areas.area_id', '=', 'areas.id')
->groupBy('areas.id')
->get();
Example 2: count with left join in laravel
$areas = Area::select('areas.*', DB::raw('count(area_id) as connections'))
->leftJoin('object_areas', 'object_areas.area_id', '=', 'areas.id')
->groupBy('areas.id')
->get();
Example 3: count with left join in laravel
$areas = Area::select('areas.*', DB::raw('count(area_id) as connections'))
->leftJoin('object_areas', 'object_areas.area_id', '=', 'areas.id')
->groupBy('areas.id')gg
->get();