Support the ongoing development of Laravel.io →
Eloquent Mail Laravel

I'm trying to make my notifications for Laravel 6 mail out effectively. I have a model (Event) that has followers (User) as a relationship - see below.

Event: $this->belongsToMany('App\User')

When an action happens, I'd like to trigger an email notification out to all the followers and a few other users. This means I'm trying to combine all the users into a single collection. My current approach is to push any individual users onto the followers collection, then remove any unwanted users based on some logic, and return a deduplicated collection that gets called....

Notification::send($users, new MemoryCreated($memory));

I'm struggling to managing the collection (removing by model (not key since it's an incremental integer) then my effort to do this $users->unique('App\User'); didn't work.

Am I approaching this correctly? How can I modify the collection helpers to use the model->id for the forget and unique methods?

Thanks!

Last updated 2 years ago.
0

OK I figured it out for anyone interested.

remove all duplicates, e.g. remove owner if already following $users = $users->unique('id');

if current user is following remove them $users = $users->reject(function ($value, $key) { return $value->id == Auth::user()->id; });

Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

illmatic illmatic Joined 28 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.