PHP code example of bkfdev / laravel-referrals

1. Go to this page and download the library: Download bkfdev/laravel-referrals library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bkfdev / laravel-referrals example snippets


$referralLink->referredUsers()

'providers' => [
    ...
    Bkfdev\Referrals\Providers\ReferralsServiceProvider::class,
    ...
];

php artisan vendor:publish --tag=referrals-config

'web' => [
    ...
    \Bkfdev\Referrals\Http\Middleware\StoreReferralCode::class,
],

...
use Bkfdev\Referrals\Events\UserReferred;

...
// overwrite registered function
public function registered(Request $request)
{
    // dispatch user referred event here
    UserReferred::dispatch(request()->cookie('ref'), $user);
}



namespace App\ReferralPrograms;

use Bkfdev\Referrals\Programs\AbstractProgram;

class ExampleProgram extends AbstractProgram {

    const ROYALTY_PERCENT = 30;

    /**
    *   It can be anything that will allow you to calculate the reward.
    *
    *   @param $rewardObject
    */
    public function reward($rewardObject)
    {
        $this->recruitUser->balance = $this->recruitUser->balance + $rewardObject * (self::ROYALTY_PERCENT/100);
        $this->recruitUser->save();
    }

}

php artisan tinker

Bkfdev\Referrals\Models\ReferralLink::create(['user_id' => 1, 'referral_program_id' => 1]);