Code Monkey home page Code Monkey logo

laravel-referral's Introduction

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:

You can click here to go to the original version

$ composer require benahmetcelik/laravel-referral

First add service providers into the config/app.php

\Questocat\Referral\ReferralServiceProvider::class,

Publish the migrations

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

Publish the config

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

Setup the model

Add UserReferral Trait to your User model.

use Questocat\Referral\Traits\UserReferral

class User extends Model
{
    use UserReferral;
}

Usage

Assigning CheckReferral Middleware To Routes.

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

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

// Or

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

App\User::create($data);

Get the referral link:

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

{{ $user->getReferralLink() }}

If you want to change user model this method use (config/refferral.php)

...

'user_model' => 'App\Custom\User\Model',
 ...

If you want to change ref code lenght this method use (config/refferral.php)

...
   'referral_length' => 10,
   ....

License

Licensed under the MIT license.

laravel-referral's People

Contributors

questocat avatar benahmetcelik avatar havenstd06 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.