towoju5/laravel-referral

A Referral System With Laravel

v1.1.1.0 2024-05-01 12:56 UTC

This package is auto-updated.

Last update: 2024-05-01 12:57:45 UTC


README

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 Towoju5/laravel-referral

First add service providers into the config/app.php

\Towoju5\Referral\ReferralServiceProvider::class,

Publish the migrations

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

Publish the config

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

Setup the model

Add UserReferral Trait to your User model.

use Towoju5\Referral\Traits\UserReferral

class User extends Model
{
    use UserReferral;
}

Usage

Assigning CheckReferral Middleware To Routes.

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

protected $routeMiddleware = [
    'referral' => \Towoju5\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\Models\User();
$user->name = 'johndoe';
$user->password = bcrypt('password');
$user->email = 'johndoe@gmail.com';
$user->save();

// Or

$data = [
    'name' => 'johndoe',
    'password' => bcrypt('password'),
    'email' => 'johndoe@gmail.com',
];

App\Models\User::create($data);

Get the referral link:

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

{{ $user->getReferralLink() }}

License

Licensed under the MIT license.