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

ActiveJuzaweb-module[Utility &amp; Helpers](/categories/utility)

juzaweb/referral
================

Juzaweb CMS Referral module

1.0.0(2y ago)115MITPHPPHP ^8.0|^8.1CI passing

Since Feb 18Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/juzaweb/referral)[ Packagist](https://packagist.org/packages/juzaweb/referral)[ RSS](/packages/juzaweb-referral/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

Juzaweb CMS Referral Module
===========================

[](#juzaweb-cms-referral-module)

The **Juzaweb Referral Module** provides a flexible and polymorphic referral system for Juzaweb CMS. It allows any model (like `User`) to generate referral codes, act as a referrer, and track referred entities.

Features
--------

[](#features)

- **Polymorphic Referrals:** Any model can refer or be referred by any other model.
- **Unique Referral Codes:** Generates unique, customizable referral codes automatically.
- **Easy Integration:** Simply add a trait to your models to enable referral functionality.

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

[](#installation)

Install via Composer:

```
composer require juzaweb/referral
```

Then, you can publish and run the migrations if required (typically handled by the Juzaweb module manager):

```
php artisan module:migrate Referral
```

Usage
-----

[](#usage)

### 1. Enable Referrals on Your Model

[](#1-enable-referrals-on-your-model)

Add the `HasReferrals` trait to any Eloquent model (e.g., your `User` model) that will participate in the referral system.

```
namespace App\Models;

use Juzaweb\Modules\Core\Models\User as BaseUser;
use Juzaweb\Modules\Referral\Traits\HasReferrals;

class User extends BaseUser
{
    use HasReferrals;
}
```

### 2. Generating Referral Codes

[](#2-generating-referral-codes)

You can generate a unique referral code statically.

```
$code = User::generateReferralCode();
```

*Note: The generator handles uniqueness automatically and increases length to prevent infinite loops.*

### 3. Creating a Referral

[](#3-creating-a-referral)

When a new entity signs up using a referral link or code, you can link the new entity (the "referred") to the existing entity (the "referrer"):

```
$referrer = User::find(1);
$referred = User::find(2);

// Make the referral
$referral = $referrer->refer($referred);
```

### 4. Retrieving Referrals

[](#4-retrieving-referrals)

You can easily retrieve all referrals sent or received by a model.

**Get all users referred by this user:**

```
$user = User::find(1);
$referralsSent = $user->referralsSent;

foreach ($referralsSent as $referral) {
    // Access the referred model instance
    $referredModel = $referral->referred;
}
```

**Get the user who referred this user:**

```
$user = User::find(2);
$referralsReceived = $user->referralsReceived;

foreach ($referralsReceived as $referral) {
    // Access the referrer model instance
    $referrerModel = $referral->referrer;
}
```

Models Overview
---------------

[](#models-overview)

- **`Referral`**: Represents a referral record. It uses polymorphic relations (`referrer_id`, `referrer_type`, `referred_id`, `referred_type`) to link two models together.
- **`ReferralCode`**: Stores the unique referral codes generated by the referrers.

Testing
-------

[](#testing)

Run tests using PHPUnit.

```
vendor/bin/phpunit
```

License
-------

[](#license)

This project is licensed under the [MIT license](LICENSE.md).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance52

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

866d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3169e8a8781068840e9300a57785089da521287dbe0279fc9cc7e8de1c1d95a9?d=identicon)[juzaweb](/maintainers/juzaweb)

---

Top Contributors

[![juzaweb](https://avatars.githubusercontent.com/u/47020363?v=4)](https://github.com/juzaweb "juzaweb (26 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (3 commits)")

### Embed Badge

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

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

###  Alternatives

[coding-libs/zkteco-php

A package for managing ZKTeco device.

194.8k](/packages/coding-libs-zkteco-php)

PHPackages © 2026

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