LaravelPackages.net
Acme Inc.
Toggle sidebar
chiwex/laravel-referral

A Referral System With Laravel

1
0
About chiwex/laravel-referral

chiwex/laravel-referral is a Laravel package for a referral system with laravel. It currently has 0 GitHub stars and 1 downloads on Packagist. Install it with composer require chiwex/laravel-referral. Discover more Laravel packages by chiwex or browse all Laravel packages to compare alternatives.

Last updated

laravel-referral

A Referral System With Laravel

StyleCI Scrutinizer Code Quality Build Status Packagist

Installation

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

$ composer require chiwex/laravel-referral

First add service providers into the config/app.php

\Chiwex\Referral\ReferralServiceProvider::class,

Publish the migrations

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

Publish the config

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

Setup the model

Add UserReferral Trait to your User model.

use Chiwex\Referral\Traits\UserReferral

class User extends Model
{
    use UserReferral;
}

Usage

Assigning CheckReferral Middleware To Routes.

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

protected $routeMiddleware = [
    'referral' => \Chiwex\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 = 'chiwex';
$user->password = bcrypt('password');
$user->email = '[email protected]';
$user->save();

// Or

$data = [
    'name' => 'chiwex',
    'password' => bcrypt('password'),
    'email' => '[email protected]',
];

App\User::create($data);

Get the referral link:

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

{{ $user->getReferralLink() }}

License

Licensed under the MIT license.

Comments