PHPackages                             jijunair/laravel-referral - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jijunair/laravel-referral

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jijunair/laravel-referral
=========================

Laravel package for a referral system

v1.0.4(1y ago)9434.5k↓57%28[1 issues](https://github.com/jijunair/laravel-referral/issues)MITPHPPHP ^7.2|^7.3|^7.4|^8.0|^8.1|^8.2

Since Jul 13Pushed 1y ago4 watchersCompare

[ Source](https://github.com/jijunair/laravel-referral)[ Packagist](https://packagist.org/packages/jijunair/laravel-referral)[ Docs](https://github.com/jijunair/laravel-referral)[ RSS](/packages/jijunair-laravel-referral/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

 [![Heading of Laravel Referral](/images/header.jpeg)](/images/header.jpeg)

 [![Latest Version on Packagist](https://camo.githubusercontent.com/96b013ea892b0ad0fc7d32e30e9ad32023eb5f5150035ffd875a46931fd031a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a696a756e6169722f6c61726176656c2d726566657272616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jijunair/laravel-referral) [![Total Downloads](https://camo.githubusercontent.com/6fa500e4523f214a870ec3d492744ce59a61af290d205766edb89266eaf45039/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a696a756e6169722f6c61726176656c2d726566657272616c)](https://packagist.org/packages/jijunair/laravel-referral) [![License](https://camo.githubusercontent.com/c569fc11184f55d7a504daf7fb1a6533adefa72a1883892e03b95beb29b62f3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a696a756e6169722f6c61726176656c2d726566657272616c)](https://packagist.org/packages/jijunair/laravel-referral)

The **Laravel Referral** package (`jijunair/laravel-referral`) is a powerful and easy-to-use package for adding referral system functionality to your Laravel applications. With this package, you can effortlessly generate referral codes, track user referrals, and reward users based on their referrals.

Key Features
------------

[](#key-features)

✅ Generate unique referral codes for users
✅ Track referrals and associate them with users
✅ Retrieve referrers and their referred users
✅ Customizable referral code length, cookie tracking, and redirection
✅ Simple trait-based integration with your `User` model

- [Installation](#installation)
    - [Configuration](#configuration)
    - [Migration](#migration)
    - [Add Trait](#add-trait)
- [Usage](#usage)
    - [Generate Referral Accounts for Existing Users](#generate-referral-accounts-for-existing-users)
    - [Get the Referrer of a User](#get-the-referrer-of-a-user)
    - [Get Referrer by Referral Code](#get-referrer-by-referral-code)
    - [Check if a User has a Referral Account](#check-if-a-user-has-a-referral-account)
    - [Create a Referral Account for a User](#create-a-referral-account-for-a-user)
    - [Get All Referrals of a User](#get-all-referrals-of-a-user)
    - [Get the Referral Link of a User](#get-the-referral-link-of-a-user)
- [Changelog](#changelog)
- [Contribution](#contributing)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via Composer by running the following command:

```
composer require jijunair/laravel-referral
```

#### Configuration

[](#configuration)

The package provides a configuration file that allows you to customize its behavior. You should publish the migration and the config/referral.php config file with:

```
php artisan vendor:publish --provider="Jijunair\LaravelReferral\Providers\ReferralServiceProvider"
```

After publishing, you can find the configuration file at config/referral.php.

Configuration KeyDescription`cookie_name`The name of the cookie that tracks referrals.`cookie_expiry`How long the referral cookie will be valid. (Default: 1 year)`route_prefix`The prefix used for referral links.`ref_code_prefix`The prefix added to the unique referral code for each user.`redirect_route`The page where users will go after clicking on a referral link.`user_model`The model class for the user.`referral_length`The length of the referral code for each user. (Default: 8 characters)These configuration options help customize the behavior of the referral system in your Laravel application. Feel free to adjust these values according to your preferences and requirements!

#### Migration

[](#migration)

After the config and migration have been published and configured, you can create the tables for this package by running:

```
 php artisan migrate
```

#### Add Trait

[](#add-trait)

Add the necessary trait to your User model:

```
use Jijunair\LaravelReferral\Traits\Referrable;

class User extends Model
{
    use Referrable;
}
```

Usage
-----

[](#usage)

#### Generate Referral Accounts for Existing Users

[](#generate-referral-accounts-for-existing-users)

To generate referral accounts for existing users, you can visit the following URL:

```
http://localhost:8000/generate-ref-accounts

```

This will generate referral codes for all existing users in your application.

#### Get the Referrer of a User

[](#get-the-referrer-of-a-user)

To get the referrer of a user, you can use the following code:

```
use Illuminate\Support\Facades\Auth;

$user = Auth::user();
$referrer = $user->referralAccount->referrer;
```

This retrieves the referrer associated with the user.

#### Get Referrer by Referral Code

[](#get-referrer-by-referral-code)

To get the referrer by referral code, you can use the following code:

```
use Jijunair\LaravelReferral\Models\Referral;
use Illuminate\Support\Facades\Cookie;

$referralCode = Cookie::get(config('referral.cookie_name'));
$referrer = Referral::userByReferralCode($referralCode);
```

This retrieves the referrer based on the referral code stored in the cookie.

#### Check if a User has a Referral Account

[](#check-if-a-user-has-a-referral-account)

To check if a user has a referral account, you can use the following code:

```
$user->hasReferralAccount();
```

This returns `true` if the user has a referral account, and `false` otherwise.

#### Create a Referral Account for a User

[](#create-a-referral-account-for-a-user)

To create a referral account for a user, you can use the following code:

```
$user->createReferralAccount($referrer->id);
```

This associates the user with the provided referrer by creating a referral account.

#### Get All Referrals of a User

[](#get-all-referrals-of-a-user)

To get all referrals under a user, you can use the following code:

```
$referrals = $user->referrals;
```

This retrieves all the referrals associated with the user.

#### Get the Referral Link of a User

[](#get-the-referral-link-of-a-user)

To get the referral link of a user, you can use the following code:

```
$referralLink = $user->getReferralLink();
```

This returns the referral link associated with the user.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Thank you for considering contributing to the Laravel Referral Package! If you have any suggestions, bug reports, or pull requests, please feel free to open an issue or submit a pull request on the GitHub repository.

License
-------

[](#license)

The Laravel Referral Package is open-source software licensed under the [MIT](LICENSE) license.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance45

Moderate activity, may be stable

Popularity44

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~164 days

Total

5

Last Release

429d ago

PHP version history (2 changes)v1.0.0PHP ^7.2|^7.3|^7.4|^8.0

v1.0.4PHP ^7.2|^7.3|^7.4|^8.0|^8.1|^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10154580?v=4)[Jiju Nair](/maintainers/jijunair)[@jijunair](https://github.com/jijunair)

---

Top Contributors

[![jijunair](https://avatars.githubusercontent.com/u/10154580?v=4)](https://github.com/jijunair "jijunair (18 commits)")[![makowskid](https://avatars.githubusercontent.com/u/6271194?v=4)](https://github.com/makowskid "makowskid (1 commits)")

---

Tags

affiliateaffiliate-trackinglaravelreferralreferral-systemlaravelpackagereferralreferral-systemaffiliatelaravel-referraljijunairuser-referral

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jijunair-laravel-referral/health.svg)

```
[![Health](https://phpackages.com/badges/jijunair-laravel-referral/health.svg)](https://phpackages.com/packages/jijunair-laravel-referral)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6804.7k6](/packages/hasinhayder-tyro)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
