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 2d 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 62% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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

631d 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://avatars.githubusercontent.com/u/7257046?v=4)[Mohamed Elogail](/maintainers/melogail)[@melogail](https://github.com/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)
```

###  Alternatives

[desandro/imagesloaded

JavaScript is all like \_You images done yet or what?\_

8.9k449.7k1](/packages/desandro-imagesloaded)[rappasoft/laravel-livewire-tables

A dynamic table component for Laravel Livewire

2.0k2.9M31](/packages/rappasoft-laravel-livewire-tables)[szeidler/composer-patches-cli

28259.3k4](/packages/szeidler-composer-patches-cli)[wa72/html-pretty-min

HTML minifier and indenter that works on the DOM tree

22231.3k8](/packages/wa72-html-pretty-min)[veewee/reflecta

Unleash the Power of Optics in your code!

13422.0k7](/packages/veewee-reflecta)[apen/additional_reports

Useful information in the reports module : xclass, ajax, cliKeys, eID, general status of the system (encoding, DB, php vars...), hooks, compare local and TER extension (diff), used content type, used plugins, ExtDirect... It can really help you during migration or new existing project (to have a global reports of the system).

14167.3k](/packages/apen-additional-reports)

PHPackages © 2026

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