Well, the OP was not very useful, but I will give him a chance! I believe that the table votescontains the actual votes cast by users by item. This means that if an element does not receive any vote, then this element identifier ( masterItemId) does not exist in the table votes.
, masterItemId. : items , itemId, masterItemId votes. SQL:
select items.itemId, ifnull(sum(votes.votes),0) as votesSum
from items left join votes on items.itemId=votes.masterItemId
where votes.voteDate between ... and ... and <other conditions>
group by items.itemId
Laravel, - , -:
$multipleitems = DB::table('items')
->leftJoin('votes','items.itemId','=','votes.masterItemId')
->select('items.itemId',DB::raw('ifnull(sum(votes.votes),0) as voteSum'))
->whereBetween('votes.voteDate',array($startDate,$endDate))
->where($condition)
->groupBy('items.temId')
->get();