In this episode, we add the ability to mention users in a text area using the '@' symbol, just like you see on many social media platforms. We start by setting up the Tribute.js library, which easily handles "mention" autocomplete functionality. You'll see how to install it via npm, pull it into your JS (we globally add it to window
for now), and grab its styles so everything looks right.
Next, we hook Tribute into our Alpine component by providing it with a hardcoded list of users—just to get things working initially. We walk through customizing how the suggestions look (like showing both username and full name). Once it’s working with those example users, we move onto pulling the real list of users from our database. For that, we make a simple PHP class called Mentionables
that gathers all users and returns them in the format Tribute expects. We then JSON-encode this data in Blade and pass it to our frontend.
We wrap up by testing the setup: add a new user and watch them appear in the mentions dropdown, and show how Tribute filters as you type. The solution still needs optimizing for larger user bases (we point out future improvements), but we've now got a solid, working MVP for user mentions in place!