PHPackages                             ibrah3m/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. ibrah3m/laravel-referral

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

ibrah3m/laravel-referral
========================

Laravel package for a referral system

2.0.0(4mo ago)03MITPHPPHP ^8.2

Since Dec 27Pushed 4mo agoCompare

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

READMEChangelogDependencies (3)Versions (2)Used By (0)

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

 [![Latest Version on GitHub](https://camo.githubusercontent.com/bca1360d3837f86c62ce7f32ef49d5e1baac9c4f33050ec2059f56542b9c6dc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6962726168336d2f6c61726176656c2d726566657272616c3f7374796c653d666c61742d737175617265)](https://github.com/ibrah3m/laravel-referral) [![GitHub stars](https://camo.githubusercontent.com/2745a6256aba1020011361b23c83c4a06baf10e2ba30554cb9317af0ac6ade5d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6962726168336d2f6c61726176656c2d726566657272616c3f7374796c653d666c61742d737175617265)](https://github.com/ibrah3m/laravel-referral) [![License](https://camo.githubusercontent.com/64847863351c3f90511f936ec82569965bb9eabea1df5fe6483edbfbf90588ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6962726168336d2f6c61726176656c2d726566657272616c)](https://github.com/ibrah3m/laravel-referral)

 [![PHP Version](https://camo.githubusercontent.com/b66a13405a9e7560deb70ef00e7fbe25d9468d71b3955cf8147095fc59e78882/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a696a756e6169722f6c61726176656c2d726566657272616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jijunair/laravel-referral) [![Laravel Version](https://camo.githubusercontent.com/5ac80bc08347d47d1d16f8fbe0fd12bdf2e22d6d6e1baebb8a5f583cfd15dd61/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jijunair/laravel-referral)

The **Laravel Referral** package (`ibrah3m/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

- [Key Features](#key-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)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

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

```
composer require ibrah3m/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="Ibrah3m\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 Ibrah3m\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 Ibrah3m\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

35

—

LowBetter than 80% of packages

Maintenance75

Regular maintenance activity

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

137d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelpackagereferralreferral-systemaffiliatelaravel-referraluser-referralibrah3m

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jijunair/laravel-referral

Laravel package for a referral system

9223.8k](/packages/jijunair-laravel-referral)[efureev/laravel-trees

Multi-Tree structures for Laravel

14253.3k4](/packages/efureev-laravel-trees)[gallib/laravel-short-url

A Laravel package to shorten urls

16516.4k](/packages/gallib-laravel-short-url)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)[pdazcom/laravel-referrals

A referrals system for a laravel projects.

301.5k](/packages/pdazcom-laravel-referrals)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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