-
app/Base/Utilities/GetRecipientsTrait.php
Open in GitHubuse App\Base\Models\User; use Illuminate\Support\Collection; trait GetRecipientsTrait { public function getRecipients($group, $ownerId): Collection { return $group->first()->members()->get() ->filter(function (User $user) use ($ownerId) { return $user->getKey() !== $ownerId; }); } }
-
app/Discussion/Observers/DiscussionObserver.php
Open in GitHubuse App\Discussion\Models\Discussion; use App\Base\Utilities\GetRecipientsTrait; use Illuminate\Support\Facades\Notification; use App\Discussion\Notifications\DiscussionCreatedNotification; class DiscussionObserver { use GetRecipientsTrait; public function created(Discussion $discussion) { Notification::send($this->getRecipients($discussion->discussionable(), $discussion->posted_by), new DiscussionCreatedNotification($discussion, $discussion->creator)); } }