questocat / laravel-referral
A Referral System With Laravel
Installs: 59 555
Dependents: 0
Suggesters: 0
Security: 0
Stars: 134
Watchers: 9
Forks: 34
Open Issues: 4
Requires
- php: >=7.0
Requires (Dev)
- laravel/laravel: ^5.5
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0|~5.0
This package is auto-updated.
Last update: 2024-11-07 23:56:30 UTC
README
A Referral System With Laravel
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 = 'zhengchaopu@gmail.com'; $user->save(); // Or $data = [ 'name' => 'zhengchaopu', 'password' => bcrypt('password'), 'email' => 'zhengchaopu@gmail.com', ]; App\User::create($data);
Get the referral link:
$user = App\User::findOrFail(1); {{ $user->getReferralLink() }}
License
Licensed under the MIT license.