All Projects → junaidnasir → Larainvite

junaidnasir / Larainvite

Licence: mit
User (signup) invitation package for laravel

Projects that are alternatives of or similar to Larainvite

Laravel Zip Validator
Laravel ZIP file content validator
Stars: ✭ 120 (-2.44%)
Mutual labels:  laravel
Payumlaravelpackage
Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
Stars: ✭ 121 (-1.63%)
Mutual labels:  laravel
Laravel Mail Editor
MailEclipse ⚡ Laravel Mailable Editor!
Stars: ✭ 1,714 (+1293.5%)
Mutual labels:  laravel
Facebook
📨 Facebook Notifications Channel for Laravel
Stars: ✭ 120 (-2.44%)
Mutual labels:  laravel
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (-1.63%)
Mutual labels:  laravel
Demo
Vanilo Demo Application
Stars: ✭ 122 (-0.81%)
Mutual labels:  laravel
Pagination
🎁 Laravel 5 Custom Pagination Presenter
Stars: ✭ 119 (-3.25%)
Mutual labels:  laravel
Sieve
A simple, clean and elegant way to filter Eloquent models.
Stars: ✭ 123 (+0%)
Mutual labels:  laravel
Rpg
Online Role Playing Game (based on Laravel)
Stars: ✭ 121 (-1.63%)
Mutual labels:  laravel
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+1308.94%)
Mutual labels:  laravel
Laravel Facebook
A Facebook bridge for Laravel
Stars: ✭ 120 (-2.44%)
Mutual labels:  laravel
Php Ext Xlswriter
🚀 PHP Extension for creating and reader XLSX files.
Stars: ✭ 1,734 (+1309.76%)
Mutual labels:  laravel
Flysystem Qcloud Cos V5
💾 Flysystem Adapter for Tencent Cloud COS V5
Stars: ✭ 122 (-0.81%)
Mutual labels:  laravel
L5 Swagger
OpenApi or Swagger integration to Laravel
Stars: ✭ 1,781 (+1347.97%)
Mutual labels:  laravel
Api Response
Simple and ready to use API response wrapper for Laravel.
Stars: ✭ 123 (+0%)
Mutual labels:  laravel
Cell Blog
基于 Laravel 7开发,支持 Markdown 语法的博客
Stars: ✭ 120 (-2.44%)
Mutual labels:  laravel
Laravel Filemanager
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
Stars: ✭ 1,688 (+1272.36%)
Mutual labels:  laravel
Laravel Meta
Metadata for Eloquent model
Stars: ✭ 124 (+0.81%)
Mutual labels:  laravel
Onramp
Easing the onramp for new or non-PHP developers to become Laravel devs.
Stars: ✭ 123 (+0%)
Mutual labels:  laravel
Roles Permissions Laravel
Roles and Permissions implementation on Laravel 5.4
Stars: ✭ 121 (-1.63%)
Mutual labels:  laravel

larainvite

User (signup) invitation package for laravel

Latest Stable Version License Total Downloads Monthly Downloads

  • v4 support laravel 8
  • v3 support laravel 5.8+, laravel 6.0 and laravel 7.0
  • v2 support laravel 5.0 to 5.8
  • v1 support laravel 4.*

larainvite is a laravel package, to allow existing users to invite others by email.

It generates referral code and keep track of status.

Installation

Begin by installing the package through Composer. Run the following command in your terminal:

composer require junaidnasir/larainvite

add the package service provider in the providers array in config/app.php:

Junaidnasir\Larainvite\LaraInviteServiceProvider::class

you may add the facade access in the aliases array:

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

publish the migration and config file:

php artisan vendor:publish --provider="Junaidnasir\Larainvite\LaraInviteServiceProvider"

migrate to create user_invitation table

php artisan migrate

edit your User model to include larainviteTrait

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

Usage

You can use facade accessor to retrieve the package controller. Examples:

$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;
});

now create routes with refCode, when user access that route you can use following methods

// 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
}

with help of new trait you have access to invitations sent by user

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

Events

larainvite fires several events

  • Junaidnasir\Larainvite\Events\Invited
  • Junaidnasir\Larainvite\Events\InvitationConsumed
  • Junaidnasir\Larainvite\Events\InvitedCanceled
  • Junaidnasir\Larainvite\Events\Expired

all of these events incloses invitation modal so you can listen to these events. include listener in EventServiceProvider.php

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

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

userInvite.php

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);
        });
}

Configurations

in config/larainvite.php you can set default expiration time in hours from current time.

'expires' => 48

you can also change user model to be used, in larainvite.php

'UserModel' => 'App\User'

you can also change invitation model to be used, in larainvite.php

'InvitationModel' => 'App\Invitation'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].