PHP code example of lopatin96 / laravel-referrals

1. Go to this page and download the library: Download lopatin96/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/ */

    

lopatin96 / laravel-referrals example snippets


use Atin\LaravelReferrals\Traits\HasReferrals;

class User extends Authenticatable
{
    use HasReferrals;

namespace App\Actions\Fortify;

…

class CreateNewUser implements CreatesNewUsers
{
    public function create(array $input): User
    {
        return DB::transaction(function () use ($input) {
            $referrerId = request()->cookie('referrer_id');
            
            cookie()->queue(cookie()->forget('referrer_id'));
            
            return tap(User::forceCreate([
                …
                'referrer_id' => User::where('id', $referrerId)->exists() ? $referrerId : null,
            ]), function (User $user) {
                $this->createTeam($user);
            });
        });

protected $middlewareGroups = [
    'web' => [
        …
        \Atin\LaravelReferrals\Middleware\HandleReferral::class, // Add your middleware here
    ],
    …
];

php artisan migrate

{{ auth()->user()->getReferralLink() }}