In this episode, we dive into setting up email notifications for users when they get mentioned in a comment. To test out sending emails locally, we get a local email testing app (like "mailhog" or "hello") up and running, and quickly configure our app's mail settings to use the right port—making sure emails don't fly into the void while we're working on things.
From there, we create a new notification class called CommentMentioned
. The idea: whenever a user is mentioned (for the first time) in a comment, they get an email letting them know. We grab the IDs of all mentioned users and notify each one using Laravel's built-in notification system.
Next up, we customize the email itself. It includes who mentioned you and provides a direct link to the comment. We use Laravel's new URI helper to nicely build fragment URLs—so when someone clicks "View comment," they're taken straight to the specific comment they were mentioned in (handy!).
To really tie it all together, we tweak the comment list to include the appropriate HTML IDs. That way, clicking the email link jumps right to the mentioned comment on the page. To wrap it up, we send a test notification—checking the local email inbox to see the new mention email in action.
Everything’s now set up so that mentioned users get notified, and in the next episode, we’ll cover how to properly test all this new functionality.