Giter Site home page Giter Site 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:

$ composer require questocat/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() }}

License

Licensed under the MIT license.

laravel-referral's People

Contributors

havenstd06 avatar questocat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-referral's Issues

Existing users

Hey there! Thanks for the package

What happens with the existing users? The id is only generated when you create an user?

Otherwise, I don't understand where to put the middleware

What about the users that are already exists?

Hey there! Thanks for the package

What happens with the existing users? The id is only generated when you create an user?

Otherwise, I don't understand where to put the middleware

Existing users

Hey there! Thanks for the package

What happens with the existing users? The id is only generated when you create an user?

Otherwise, I don't understand where to put the middleware

Register user

How can i register an user and fill the referred_by field ?

Call to undefined function Questocat\Referral\Traits\str_random()

Symfony\Component\Debug\Exception\FatalThrowableError  : Call to undefined function Questocat\Referral\Traits\str_random()

  at /var/www/cportal/data/www/mysite.com/vendor/questocat/laravel-referral/src/Traits/UserReferral.php:47
    43|     {
    44|         $length = config('referral.referral_length', 5);
    45| 
    46|         do {
  > 47|             $referral = str_random($length);
    48|         } while (static::referralExists($referral));
    49| 
    50|         return $referral;
    51|     }

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.