In this episode, we're making usernames in comments clickable, so you can jump straight to a user's profile just by clicking their @name! (Think like how GitHub issues work.) We start by enabling Markdown parsing in our comments using the popular Laravel Markdown package. Once that's set up, we install and configure an extension (from the league/commonmark package) that recognizes mentions, i.e., any @username, and turns them into links.
But here's the trick: we only want to link usernames that actually exist in our database. To pull this off, we set up a custom mention generator class. This class checks if the mentioned username is real, and only then generates the profile link. We walk through how to update our Markdown config to use this logic, clear the config cache (so the changes take effect), and build a quick Livewire profile component + route for the user profiles.
At the end, you’ll see that when you mention a valid user like @tabby
, it becomes a clickable link to their profile, but if you mention a random or non-existent user, it'll just show as plain text. No more 404s for mistyped names! Plus, the mentions are cached so you don't have to worry about unnecessary database queries. That's clickable, mentionable usernames sorted with Markdown in Laravel!