theUnforgiven
3 months ago

Getting users from a foreach, but only sending an email once

Posted 3 months ago by theUnforgiven

Hi all, Hope everyone is having a good start to the week.

I have a small hurdle I'm trying to overcome. I have a foreach loop to grab users and then I want each user to receive an email, but only once, whereas in the current code (below) it obviously sends it multiple times.

$users = User::where('id', $chat->user_id)->get();
            
foreach($users as $key => $user) {
     
     \Mail::to($user->email)
              ->later($when, new ConversationTranscript($users, $chats, $group));
}

Please sign in or create an account to participate in this conversation.