PHPackages                             asciisd/referrals-laravel - 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. asciisd/referrals-laravel

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

asciisd/referrals-laravel
=========================

Adding referrals feature to your laravel project

v2.4.3(1y ago)0115MITPHP

Since Sep 24Pushed 1y ago2 watchersCompare

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

READMEChangelog (10)DependenciesVersions (36)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f6113a3ec6e863fc780c154133689b198d652b1b62ed8b3a203372e51c6244bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617363696973642f726566657272616c732d6c61726176656c2e7376673f7374796c653d666c6174)](https://packagist.org/packages/asciisd/referrals-laravel)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/f00831278c1da5f6f848363344c34059aac27109fbee4e3ed5eaeb5dd08b18a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617363696973642f726566657272616c732d6c61726176656c2e7376673f7374796c653d666c6174)](https://packagist.org/packages/asciisd/referrals-laravel)

Referrals package for laravel
=============================

[](#referrals-package-for-laravel)

Compatible with laravel &gt;= 8.0

Installation:
-------------

[](#installation)

To install the package in your project you need to require it with composer.

```
$ composer require asciisd/referrals-laravel

```

Configs:
--------

[](#configs)

First, you need to set the package configurations by publishing the config file to your project `config` directory.

To publish the `referrals.php` config file use the `publish` command:

```
$ php artisan vendor:publish

```

and from the providers list choose the `ReferralsLaravelServiceProvider`.

Next, inside your `.env` file, add the route you want the invited user to be redirected to.

```
referral_route='route_name'
```

By default, the invited user will be redirected to the registration page with route `register`.

If you plan to use cookies to save the referral token, by default, the cookie life-time is set to 24 hours. You can customize the cookie life-time by setting the `referral_token_cookie_lifetime` inside your `.env` file.

```
referral_token_cookie_lifetime=1440
```

Usage:
------

[](#usage)

To use the package in your project, simply use the `Referrable` trait in your users model.

```
class User extends Authenticatable implements MustVerifyEmail{
     /*...*/
     use \Asciisd\ReferralsLaravel\app\Traits\Referrerable;
     /*...*/

}
```

Next, use `php artisan migrate` to migrate the database file. This migration wll create new table `referrals`. A one-to-many relationship is created with the users table.

The `referrer_id` is the id of the user who sent the invitation link.

### Saving the referral token to a cookie:

[](#saving-the-referral-token-to-a-cookie)

For further usage of the referral token, you can use `ReferralsLaravel` middleware inside your `Kernel.php` file.

You can set and alias to your middleware to use it with specific routes:

```
protected $middlewareAliases = [
    /*...*/
    'referrals' => \Asciisd\ReferralsLaravel\app\Http\Middleware\ReferralsLaravel::class,
];
```

Or you can set it to any of your middleware groups:

```
protected $middlewareGroups = [
        'web' => [
            /*...*/
            \Asciisd\ReferralsLaravel\app\Http\Middleware\ReferralsLaravel::class,
        ],
        /*...*/
]
```

### Retrieving Referral Data:

[](#retrieving-referral-data)

To get all user referrals user `referrer` relationship property along with user object.

```
foreach ($user->referrals as $referral)
{
    $referral->referral_token;
}
```

---

To get user referral details from the referrals table use the property `referrals`.

```
// Get authenticated referral token
auth()->user()->referral->referral_token;
```

---

To check if the user is invited by another user, use the `isReferred()` method on the user object.

```
// Return true if the user is invited
// and false if the user was not invited by other user.
$user->isReferred();
```

---

To check of the user has referral token or not use the `hasReferralToken()` method.

```
// Return true if the user has referral token, or false if not.
$user->hasReferralToken();
```

---

To generate user referral token, use the `generateReferalToken()` method. The method checks if the user has referral token or not, then it generated the referrals token.

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

---

To get the referral link you can either add `referral_link` attribute to the `$append` array inside `User` model and use it as user attribute,

```
protected $append = ['referral_link'];
```

Or, you can use the `getReferralLink()` method with the user object.

```
// Get the referral link with the user redirect route
// ex: https://mydomain.com/register?ref=34532234
$user->getReferralLink();
```

---

To get user referral token you can either add `referral_token` attribute to the `$append` array inside the `User` model and use it as attribute,

```
protected $append = ['referral_token'];
```

Or, you can use the `getReferralToken()` method with the user object.

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

Register with Nova
------------------

[](#register-with-nova)

Add nova resource `Referral` will be automatically published during publishing the service provider, to use the package with Nova just add the `Referral` resource to `NovaServiceProvider` file to register it inside your nova.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% 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 ~11 days

Recently: every ~93 days

Total

35

Last Release

577d ago

Major Versions

v1.0.16 → v2.0.02023-10-03

v1.1.0 → v2.0.12023-10-05

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77636067?v=4)[ASCII SD](/maintainers/asciisd)[@asciisd](https://github.com/asciisd)

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

---

Top Contributors

[![melogail](https://avatars.githubusercontent.com/u/7257046?v=4)](https://github.com/melogail "melogail (45 commits)")[![aemaddin](https://avatars.githubusercontent.com/u/11630742?v=4)](https://github.com/aemaddin "aemaddin (6 commits)")

### Embed Badge

![Health badge](/badges/asciisd-referrals-laravel/health.svg)

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

PHPackages © 2026

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