PHPackages                             temian/referral-system - 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. temian/referral-system

ActiveLibrary

temian/referral-system
======================

Laravel package for a referral system

026PHP

Since Jun 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Temian1/laravel-referral-system)[ Packagist](https://packagist.org/packages/temian/referral-system)[ RSS](/packages/temian-referral-system/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)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 "jijunair/laravel-referral" package is a custom Laravel package that provides referral code functionality for your Laravel applications. It allows you to generate referral codes, associate them with users, retrieve users based on their referral codes and all other related features.

- [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 temian/referral-system
```

#### 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

15

—

LowBetter than 5% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5332b731e1d74292dd2514693df159822027cdea967e29ce79206d3e5d97d17?d=identicon)[Kikismedia](/maintainers/Kikismedia)

---

Top Contributors

[![Temian1](https://avatars.githubusercontent.com/u/39234980?v=4)](https://github.com/Temian1 "Temian1 (7 commits)")

### Embed Badge

![Health badge](/badges/temian-referral-system/health.svg)

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

PHPackages © 2026

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