laravel get count from join code example
Example 1: join table laravel count
DB::table('users')
->join('contacts', 'users.id', '=', 'contacts.user_id')
->join('orders', 'users.id', '=', 'orders.user_id')
->select('users.id', 'contacts.phone', 'orders.price')
->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();