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

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

brucelampson/laravel-simple-referrals
=====================================

A referrals system for a laravel projects.

1.3.0(7y ago)112MITPHPPHP ^7.0

Since Sep 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/BruceLampson/laravel-simple-referrals)[ Packagist](https://packagist.org/packages/brucelampson/laravel-simple-referrals)[ Docs](https://github.com/BruceLampson/laravel-simple-referrals)[ RSS](/packages/brucelampson-laravel-simple-referrals/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (9)Used By (0)

Simple Referrals system for Laravel
===================================

[](#simple-referrals-system-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/421c74bdda05518137df5fa614cb066729998d9d1325fd70a0d5d9116f40f5a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7064617a636f6d2f6c61726176656c2d726566657272616c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pdazcom/laravel-referrals)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/9abb4f5a97eafb7497a7ecc07120ee5ba7ca02c352086b60c21b166b02f8f647/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7064617a636f6d2f6c61726176656c2d726566657272616c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pdazcom/laravel-referrals)

A simple system of referrals with the ability to assign different programs for different users.

This package was created based on the [lesson](https://blog.damirmiladinov.com/laravel/building-laravel-referral-system.html#.Wc4eA6xJaHo)author is Damir Miladinov, with some minor changes, for which I express my gratitude to him.

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

[](#installation)

Via Composer

```
$ composer require pdazcom/laravel-referrals
```

Then in config/app.php add service-provider and facade alias:

```
'providers' => [
    ...
    Pdazcom\Referrals\Providers\ReferralsServiceProvider::class,
    ...
];

```

Usage
-----

[](#usage)

First of all you need to run:

```
php artisan vendor:publish --provider='Pdazcom\Referrals\Providers\ReferralsServiceProvider'

```

Then change new migrations if it need and run `php artisan migrate`

Add middleware to your `web` group in `Http/Kernel.php`:

```
'web' => [
    ...
    \Pdazcom\Referrals\Http\Middleware\StoreReferralCode::class,
],

```

Add `Pdazcom\Referrals\Traits\ReferralsMember` to your `Users` model:

```
    class User extends Authenticatable {
        use ReferralsMember;
        ...
    }

```

Then in `Http/Controllers/Auth/RegisterController.php` add event dispatcher:

```
...
use Pdazcom\Referrals\Events\UserReferred;

...
// overwrite registered function
public function registered(Request $request)
{
    // dispatch user referred event here
    event(new UserReferred(request()->cookie('ref'), $user));
}

```

From this point all referral links would be attach new users as referrals to users owners of this links.

And then you need to create a referral program in DB and attach it to users by `referral_program_id` field:

```
    php artisan tinker

    Pdazcom\Referrals\Models\ReferralProgram::create(['name'=>'example', 'title' => 'Example Program', 'description' => 'Laravel Referrals made easy thanks to laravel-referrals package based on an article by Damir Miladinov,', 'uri' => 'register']);

```

add association to config `referrals.programs`:

```
    ...
    'example' => App\ReferralPrograms\ExampleProgram.php

```

and create an reward class `App\ReferralPrograms\ExampleProgram.php` for referral program:

```
