DB::raw()
is use to create a raw expression, so you have to use full table name.
Laravel Query Builder has an inbuilt function for getting table prefix DB::getTablePrefix()
Replace the above code with this and it will work.
return DB::table('table1')
->join('table2', 'table1.id', '=', 'table2.id')
->where('table1.user_id', '=', $userId)
->whereMonth('table2.date', '=', $month)
->whereYear('table2.date', '=', $year)
->select('table2.*', DB::raw('SUM(' . DB::getTablePrefix() . 'table1.count) AS count_single'))
->groupby('table2.id')
->get();
Reference: