DEV Community

Discussion on: Let's build a super simple referral system with Laravel

Collapse
 
cyprian_dev profile image
Cyprian

So for those who would be using Laravel 8 with jetstream, this stack uses Fortify for authentication and i quote from laravel documentation 'Fortify does not provide its own user interface, it is meant to be paired with your own user interface which makes requests to the routes it registers'. if that is hard to understand then follow the laravel.com/docs/8.x/fortify#intro... for clarity or drop a comment below.

So let's get to the chase. The most important thing in this system is the session that Mr Simi set to cache a session variable named 'referrer' if the register route contains a ref query parameter. now go to App\Providers\FortiftyServiceProvider in the boot() method and paste the code below

Fortify::registerView(function(Request $request) {
if ($request->has('ref')) {
session(['referrer' => $request->query('ref')]);
}
return view('auth.register');
});
Now the code is doing the same as that in the registerController.

Secondly, after caching the ref=user and getting the user's id, you would need to pass in this data in the create() method. You will find this file in the App\Actions\Foritfy\CreateNewUser class. Like what i did, i replaced the codes in this file with that of the RegisterController and then pass in the

    $referrer = User::whereUsername(session()->pull('referrer'))->first();
Enter fullscreen mode Exit fullscreen mode

This is the code that pulls the referrer's credentials and parses it in to create a new user. Every other thing stays the same from the User class and from the migration class file too.

It worked for me because i was using laravel 8 for a referral system project. Like i said, drop a comment if you have any challanges below...Cheers

Collapse
 
dotcorps profile image
dotcorps

where to write Notification code

Collapse
 
simioluwatomi profile image
Simi Oluwatomi

You have to create a notification. Kindly refer to the notification section of the Laravel docs to get started with that

laravel.com/docs/8.x/notifications

Thread Thread
 
jhims profile image
Willy

How can I get in touch with you? a means of contact

Thread Thread
 
simioluwatomi profile image
Simi Oluwatomi

You can send me a tweet on X (formerly Twitter)

Thread Thread
 
jhims profile image
Willy

unable to send message by x

Thread Thread
 
simioluwatomi profile image
Simi Oluwatomi

Send me a mail at deifilius1@gmail.com

Collapse
 
simioluwatomi profile image
Simi Oluwatomi

Thanks! I should update this tutorial to reflect the changes in Laravel since it was written but I'm currently swamped with work.

Thanks once again

Collapse
 
cyprian_dev profile image
Cyprian

Okay boss.

Collapse
 
sarjid profile image
Sarjid Islam Habil • Edited

Thanks it's work fine in laravel 8..ihave make refferel system just 40 minutes.. Thanks for Your Help..

Collapse
 
reubendickson profile image
ReubenDickson

Thanks for this guys. I'm new to Laravel. The project I'm working on includes referrals system and I'm using Jetstream. Would you like to share what you've done please. Thanks