PHPackages                             tlsgroup/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. [Admin Panels](/categories/admin)
4. /
5. tlsgroup/laravel-referral

ActiveLibrary[Admin Panels](/categories/admin)

tlsgroup/laravel-referral
=========================

Laravel package for a referral system

1.0.2(1y ago)04MITPHPPHP &gt;=8.2.0

Since Aug 7Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

The "TLSGROUP/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 TLSGROUP/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="TLSGROUP\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 TLSGROUP\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 TLSGROUP\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.

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~25 days

Total

3

Last Release

593d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c349b2f9625b5e806b5a5112d3c6a439fb8d7250cca28a652fe47be275b7510?d=identicon)[TLSGROUP](/maintainers/TLSGROUP)

---

Top Contributors

[![TLSGROUP](https://avatars.githubusercontent.com/u/45121545?v=4)](https://github.com/TLSGROUP "TLSGROUP (3 commits)")

---

Tags

laravelpackagereferralreferral-systemaffiliatelaravel-referraluser-referral

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jijunair/laravel-referral

Laravel package for a referral system

9223.8k](/packages/jijunair-laravel-referral)[andreaselia/analytics

Analytics for the Laravel framework.

19719.5k2](/packages/andreaselia-analytics)[pdazcom/laravel-referrals

A referrals system for a laravel projects.

301.5k](/packages/pdazcom-laravel-referrals)[atnic/laravel-admin-lte

Laravel Package for integrating AdminLTE template and this package is Laravel Mix friendly.

256.4k](/packages/atnic-laravel-admin-lte)

PHPackages © 2026

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