$counts = DB::select(DB::raw('select Year(FROM_UNIXTIME(time)) as year, Month(FROM_UNIXTIME(time)) as month, Day(FROM_UNIXTIME(time)) as day, Count(*) as count
FROM tweets
where year(FROM_UNIXTIME(time)) = '.$year.'
and month(FROM_UNIXTIME(time)) = '.$month.'
' . ($ids ? 'where id in (' . implode(',', $ids) . ')' : '') . '
GROUP BY Year(FROM_UNIXTIME(time)), Month(FROM_UNIXTIME(time)), Day(FROM_UNIXTIME(time))'));