PHP code example of junaidnasir / larainvite

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

    

junaidnasir / larainvite example snippets


Junaidnasir\Larainvite\LaraInviteServiceProvider::class

'Invite'  => Junaidnasir\Larainvite\Facades\Invite::class

use Junaidnasir\Larainvite\InviteTrait;
class user ... {
    use InviteTrait;
}

$user = Auth::user();
//Invite::invite(EMAIL, REFERRAL_ID); 
$refCode = Invite::invite('[email protected]', $user->id);
//or 
//Invite::invite(EMAIL, REFERRAL_ID, EXPIRATION); 
$refCode = Invite::invite('[email protected]', $user->id, '2016-12-31 10:00:00');
//or
//Invite::invite(EMAIL, REFERRAL_ID, EXPIRATION, BEFORE_SAVE_CALLBACK); 
$refCode = Invite::invite($to, Auth::user()->id, Carbon::now()->addYear(1),
                      function(/* InvitationModel, see Configurations */ $invitation) use ($someValue) {
      $invitation->someParam = $someValue;
});

// Get route
$code = Request::input('code');
if( Invite::isValid($code))
{
    $invitation = Invite::get($code); //retrieve invitation modal
    $invited_email = $invitation->email;
    $referral_user = $invitation->user;

    // show signup form
} else {
    $status = Invite::status($code);
    // show error or show simple signup form
}

// Post route
$code = Request::input('code');
$email = Request::input('signup_email');
if( Invite::isAllowed($code,$email) ){
    // Register this user
    Invite::consume($code);
} else {
    // either refCode is inavalid, or provided email was not invited against this refCode
}

$user= User::find(1);
$invitations = $user->invitations;
$count = $user->invitations()->count();

use Junaidnasir\Larainvite\Events\Invited;
use App\Listeners\SendUserInvitationNotification;

protected $listen = [
    Invited::class => [
        SendUserInvitationNotification::class,
    ],
];

public function handle($invitation)
{
    \Mail::queue('invitations.emailBody', $invitation, function ($m) use ($invitation) {
            $m->from('From Address', 'Your App Name');
            $m->to($invitation->email);
            $m->subject("You have been invited by ". $invitation->user->name);
        });
}

'expires' => 48

'UserModel' => 'App\User'

'InvitationModel' => 'App\Invitation'
bash
php artisan vendor:publish --provider="Junaidnasir\Larainvite\LaraInviteServiceProvider"
bash
php artisan migrate