Affiliate based user registration?


I want to tweak the registration form, to allow for “affiliate” type registrations, so that existing users, can send invitation links to other people to invite them to register.

I want to save the original user’s id,along with the registration form, and keep it in the database.

So I will know each new user was invited by which other previous user.

Could you give me a starting point, or any tips for this?


You will need to create a ReferralProgram model (with fields such as name, uri, lifetime_minutes) that will represent a single referral campaign. For instance, invite a friend to register and win free credits. The referral program model will have a name and url to where the link will point.
Create the ReferralLink model (with fields such as user_id, referral_program_id, code ) then make use of this uuid php package to generate unique referral codes. These codes will be used to track links and relate them to original users who shared them. This will enable each user to be involved in program using a single link for that program.
CreateRelationship model (with fields such us referral_link_id, user_id) to store relationships between user providing referral link and user using it.
Get links for every referral program available by adding adding the following code sample in your extended UF user model

public function getReferrals()
    return ReferralProgram::all()->map(function ($program) {
        return ReferralLink::getReferral($this, $program);

Then list available refferals to user in the user dashboard .
Now, on handling referral links. You will somehow need to capture the refget parameter from referral link and store it in the cookie, so when desired user action is triggered you can reward both participants.
To reward Users, you will need to fire event and listener to do the rest after adding user and referral code to it.
Remember to extend UF user model and also you should be doing all of the above in your cusom sprinkle.
Cookies should be stored in an array.