LadyDeathKZN's avatar

User group_id Team to have bulk mail system

Hi, I have my users with group_id and group with just a title (team, as example).

I want to setup a bulk mail system, where the user with group_id that corresponds with team to recieve the emails.

I have setup the relationships in the models as I am using the group_id in a form.

I have something as such:

foreach($user->group->id === 'team') {
      Mail::send('upload.email')
      ->from('[email protected]')
      ->to($user->email)
      ->subject(Upload from '$client->upload')
}

return redirect(route('home');

The idea is that when a client uploads a file when it is done, an email is sent to the entire 'team' notifying them that there is a new upload.

I have never done this before, a basic email yes, but nothing more. Any help would be appreciated. The code is going in the ClientUploadController.

0 likes
2 replies
bobbybouwmann's avatar
Level 88

Well the idea is simply right. You already have the group based on the current user. So you only need to grab the users from the group and then loop over them and send an email

foreach($user->group->users as $user) {
    // Send your mail here
}

Note that sending emails are slow. So if you need to send a bulk of emails a queue might be better. You can find good examples about that in the docs as well ;)

LadyDeathKZN's avatar

Thank you so much for the quick reply! I will def. Implement a queue system. Thank you for the help!

Please or to participate in this conversation.