In this episode, we work on getting the referral link visible on the referral dashboard so users can easily share their unique link with others. We start by thinking about how we want the dashboard layout to look, and we decide to borrow some structure from the profile edit page to keep things consistent. This involves copying out a partial, tweaking it, and setting up a nice text input that will eventually display the user's referral link.
We also set up a new controller and define a route that actually serves the referral landing page using route model binding. After that, we add a handy method (referralLink()
) to our user model (or trait) so anywhere in the app we need the user's referral link, it's just a method call away.
To make the interface user-friendly, we wire up a text input pre-filled with the user's referral link and throw in a "Copy link" button for easy sharing. We tidy things up with a read-only attribute so users can't accidentally modify the link. By the end of the episode, we've got the referral link showing up properly, styled to match our app, and ready to be shared – though the copy-to-clipboard feature will be built in the next episode. It's all set up so you or your users can start inviting people as soon as we're done!