i using sendgrid smtp send mail through site. using sendgrid event webhook record of opens/clicks/bounces.
sendgrid tracks unique opens on internal dashboard , show users same info.
schema
------------------------------------------ userid | emailid | msg_email | event| ------------------------------------------ 1 | 27898 | test@test.com | open |
basically, need find records with:
event == "open"
where userid == $userid
count distinct msg_email each emailid.
i stuck, think way approach run query grabs emails userid , event == "open". group them emailid.
$query = emailstats::where('userid', '=', $userid) ->where('event', '=', 'open') ->groupby('emailid') ->get();
then loop through each group , grab count of distinct email addresses.
i cannot figure out how loop through each "group" find distinct email address.
is there approach should considering?
laravel has collection method "unique" this. pretty easy after found it:
$query = emailstats::where('userid', '=', $userid) ->where('event', '=', 'open') ->groupby('emailid') ->get(); $unique = $query->unique(function ($item) { return $item['emailid'].$item['msg_email']; });