please try this:
$locationsQuery = DB::table('locations')
->join('contractor_location', 'locations.id', '=', 'contractor_location.location_id')
->join('contractors', 'contractor_location.contractor_id', '=', 'contractors.id')
->select('locations.city','locations.latitude','locations.longitude')
->where('locations.published',1)
->where('contractors.published',1)
//->groupBy('locations.city')
->orderBy('locations.title','ASC');
$locations = DB::select("SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); {$locationsQuery->toSql()}", $locationsQuery->getBindings());