Add phone verification workflows to your Laravel users powered by Vonage verify api.
First make sure to configure the repository in your composer.json by running:
composer config repositories.phone-verification vcs https://github.com/Wingly-Company/phone-verification
Then install the package by running:
composer require wingly/phone-verification
Wingly phone verification service provider registers its own database migration directory. The migrations will add a phone_number
, phone_verification_token
and phone_verified_at
columns to the users table.
php artisan migrate
With the package config file you can customize your workflow and your brand. Please check the Vonage documentation for more information.
You need to set your VONAGE_KEY
and VONAGE_SECRET
enviroment variables in order to use this package.
You need to add the VerifiesPhoneNumber
trait to your User
model.
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Wingly\PhoneVerification\VerifiesPhoneNumber;
class User extends Authenticatable
{
use VerifiesPhoneNumber;
}
To send a PIN code to a phone number you can use the sendPhoneVerificationCode
method.
The method will call Vonage and initialize a verification workflow. You can optionally pass any options that you want to override.
$user = User::find(1);
$user->sendPhoneVerificationCode(['code_length' => 6]);
When the user receives the PIN and enters it into your application you can verify the validity of the code
by using the checkPhoneVerificationCode
method.
$user = User::find(1);
$user->checkPhoneVerificationCode($code); // true/false
You can check if a user has a verified number by using the hasVerifiedPhoneNumber
method.
$user = User::find(1);
$user->hasVerifiedPhoneNumber(); // true/false