A Referral System With Laravel

1.0.0 2020-02-08 20:03 UTC

This package is not auto-updated.

Last update: 2024-05-19 01:59:52 UTC


A Referral System With Laravel

StyleCI Scrutinizer Code Quality Build Status Packagist


Via Composer to add the package to your project's dependencies:

$ composer require blok/laravel-referral "~1.0"

First add service providers into the config/app.php


Publish the migrations

$ php artisan vendor:publish --provider="Blok\Referral\ReferralServiceProvider" --tag="migrations"

Publish the config

$ php artisan vendor:publish --provider="Blok\Referral\ReferralServiceProvider" --tag="config"

Setup the model

Add UserReferral Trait to your User model.

use Blok\Referral\Traits\UserReferral

class User extends Model
    use UserReferral;


Assigning CheckReferral Middleware To Routes.

// Within App\Http\Kernel Class...

protected $routeMiddleware = [
    'referral' => \Blok\Referral\Http\Middleware\CheckReferral::class,

Once the middleware has been defined in the HTTP kernel, you may use the middleware method to assign middleware to a route:

Route::get('/', 'HomeController@index')->middleware('referral');

Now you can create the user:

$user = new App\User();
$user->name = 'zhengchaopu';
$user->password = bcrypt('password');
$user->email = '';

// Or

$data = [
    'name' => 'zhengchaopu',
    'password' => bcrypt('password'),
    'email' => '',


Get the referral link:

$user = App\User::findOrFail(1);

{{ $user->getReferralLink() }}


Licensed under the MIT license.