Giter Club home page Giter Club logo

larainvite's Introduction

larainvite

User (signup) invitation package for laravel

Latest Stable Version License Total Downloads Monthly Downloads

  • v5 support laravel 9
  • 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'

larainvite's People

Contributors

bmichotte avatar chellem avatar dariusiii avatar eazyserver avatar jimhill avatar junaidnasir avatar lamberski avatar laravel-shift avatar sgotre avatar uniconstructor avatar valeryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

larainvite's Issues

Can you add phonenumber

Hey this is great package. I need user phone number because i m building social app. Can u add this functionality?

Thanks:D

'status' column in user_invitations does not accept 'Null' value

Hi there, I came across this issue while fixing a project. The database I am using is on a sql server (so maybe why no other have this issue?). The only way I could get your package to work is if I added this line to the save function in LaraInvite.php $this->instance->status = "pending"; .

Not too sure if that is correct but it works. Hopefully, this will help anyone who has the same issue.

Best,

Vanida

Laravel 9 Support

Now that Laravel 9 is out it would be great if this package could support it ๐Ÿ‘๐Ÿป

Laravel 10 Support

Now that Laravel 10 is out it would be great if this package could support it ๐Ÿ‘๐Ÿป

Events in more detail?

Possible to get a bit more of an explanation of the events.

My eventsService Provider is

<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'junaidnasir.larainvite.invited' => [
            'App\Listeners\userInvite',
        ],
    ];

    /**
     * Register any other events for your application.
     *
     * @param  \Illuminate\Contracts\Events\Dispatcher  $events
     * @return void
     */
    public function boot(DispatcherContract $events)
    {
        parent::boot($events);

        //
    }
}

and if i create 'App\Listeners\userInvite' with the provided code it gives

ReflectionException in Container.php line 738: Class App\Listeners\userInvite does not exist

tried to use php artisan event:generate but could not get it to generate anything.

Not used the event system before so not sure what i should be seeing.

Can be configure name of attribute insead of user_id

First of all, it's a great library.

I would like to propose a way to change the name of the attribute user_id into user_invitations table.

For instance, I've been working with the following settings:

Account
user_id
company_id

User
id
name

Company
id
name

In my case, the responsibility for making invitations is Account Model, instead of Auth/User.

Ok, I 'll save the account_id into user_invitations table as the user_id attribute, but if I could configure the name of the attribute, could be easy to identify the relation.

You understand that I mean?

Does not install on Laravel 11

Getting the following error when trying to install the package:

our requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires junaidnasir/larainvite ^6.0 -> satisfiable by junaidnasir/larainvite[v6.0.0].
    - junaidnasir/larainvite v6.0.0 requires illuminate/support ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0 -> found illuminate/support[v5.8.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27
, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.3] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require junaidnasir/larainvite:*" to figure out if any version is installable, or "composer require junaidnasir/la
rainvite:^2.1" if you know which you need.

Undefined property: Junaidnasir\Larainvite\Events\Invited::$email

Hello,

I have this error when i tried to send an invitation to my user.

When I upgraded to version 4.x, I had to change the event listener like that:

Before

// App\Providers\EventServiceProvider
protected $listen = [
        'junaidnasir.larainvite.invited' => [
            'App\Listeners\UserInvite',
        ],
];

After

// App\Providers\
protected $listen = [
        Invited::class => [
            'App\Listeners\UserInvite',
        ],
];

After that, I had the following error:
Undefined property: Junaidnasir\Larainvite\Events\Invited::$email

For now, I found this fix:

Before

// App\Listeners\UserInvite
public function handle($invitation)
{
        Mail::to($invitation->email)->send(new UserInviteMail($invitation->code, $invitation->email));
}

After

// App\Listeners\UserInvite
public function handle($invitation)
{
        Mail::to($invitation->invitation->email)->send(new UserInviteMail($invitation->invitation->code, $invitation->invitation->email));
}

Documentation in more detail.

I am new in Laravel. Can you please share some piece of application where you have used this package to full extent. Can you please explain the package's workflow and functionality a bit more. Can you please give a demo of how to make it work. @junaidnasir

\Invite::isValid throws Exception

Hi, whe using is valid to validate a token, if the token is not in the DB it will throw a (PHP generic) exception, instead of returning false.

is this the intended behaviour?

Laravel 6.0 support

I , and probably other users too, would like to have Laravel 6.0 supported by this package.

Support Multiple providers

Hello and +1 for this package. However I don't see how one can use this with multiple providers as in the system I am working with. Each of these providers can invite other users. I was thinking making the user_id and user_type as a morph() will make it more suitable for flexible cases. Let me know what you think

Maintainer proposal

Hello,

I have no idea how to contact you directly, so I create this issue because I'm willing to be the new maintainer of this project.

I'm using it and currently working on a fork to meet our needs.

What would be the conditions to be the new maintainer ?

Regards,
Fred

Saving extra info with the invite

What steps are needed to save some extra piece of information with an invite? For example, my users can send an invitation to an email address, asking them to join one of their owned "rooms". Obviously I can't send room-id to invited guy in the url (people can change it). In fact, I shouldn't be sending the room id to the recipient in any form. It should just be saved with the invitation at sending time. I would then retrieve it when the invited guy comes in and sends me the refCode.

See what I mean?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.