/** * @param Post $reply * @param array $mentioned */ protected function sync(Post $reply, array $mentioned) { $reply->mentionsPosts()->sync($mentioned); $posts = Post::with('user')->whereIn('id', $mentioned)->get()->filter(function ($post) use($reply) { return $post->user && $post->user->id !== $reply->user_id; })->all(); foreach ($posts as $post) { $this->notifications->sync(new PostMentionedBlueprint($post, $reply), [$post->user]); } }