PHPackages                             kwidoo/sms-verification - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kwidoo/sms-verification

ActiveLibrary

kwidoo/sms-verification
=======================

A flexible SMS verification package supporting multiple providers

1.1.1(1y ago)0212MITPHPPHP ^8.2CI passing

Since Mar 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kwidoo/sms-verification)[ Packagist](https://packagist.org/packages/kwidoo/sms-verification)[ Docs](https://github.com/kwidoo/sms-verification)[ RSS](/packages/kwidoo-sms-verification/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (8)Used By (2)

[![Latest Version on Packagist](https://camo.githubusercontent.com/50e530c46b4e311bd863fd631939d87148e246690b659bffe057a8fbfc3355b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b7769646f6f2f736d732d766572696669636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwidoo/sms-verification)[![Total Downloads](https://camo.githubusercontent.com/791735375952f9541dda634fa048a017993b5c2018fb1e9e4d396935d21d0dec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b7769646f6f2f736d732d766572696669636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwidoo/sms-verification)[![GitHub Actions](https://github.com/kwidoo/sms-verification/actions/workflows/main.yml/badge.svg)](https://github.com/kwidoo/sms-verification/actions/workflows/main.yml/badge.svg)

---

Laravel SMS Verification
========================

[](#laravel-sms-verification)

> A Laravel package for sending and validating SMS-based verification codes through multiple providers (e.g., **Twilio**, **Vonage**, or any custom provider\*\*).

Overview
--------

[](#overview)

- **Round Robin Support**: Optionally cycle through multiple providers.
- **Pluggable Architecture**: Implement your own custom verifier(s).
- **Abstracted Interface**: A single interface for `create()` (sending code) and `validate()` (checking code).

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Round Robin Usage](#round-robin-usage)
    - [Custom Verifiers](#custom-verifiers)
- [Console Command](#console-command)
- [Example Code](#example-code)
- [Credits](#credits)
- [License](#license)
- [TODO](#todo)

---

Installation
------------

[](#installation)

1. **Require via Composer**:

    ```
    composer require kwidoo/sms-verification
    ```
2. **Publish Config (Optional)**:

    This will publish `sms-verification.php` into your Laravel `config` directory.

    ```
    php artisan vendor:publish --provider="Kwidoo\SmsVerification\SmsVerificationProvider" --tag="sms-verification-config"
    ```
3. **Configure Environment Variables**:

    In your `.env` file, make sure to set the appropriate credentials for your desired providers. For example:

    ```
    # Twilio
    TWILIO_SID=xxxxxxxxxx
    TWILIO_AUTH_TOKEN=xxxxxxxxxx
    TWILIO_VERIFY_SID=xxxxxxxxxx

    # Vonage
    VONAGE_API_KEY=xxxxxxxxxx
    VONAGE_API_SECRET=xxxxxxxxxx
    VONAGE_BRAND="My Awesome App"
    ```

---

Configuration
-------------

[](#configuration)

The default configuration file `sms-verification.php` looks like this:

```
return [
    'verifiers' => [
        'twilio' => \Kwidoo\SmsVerification\Verifiers\TwilioVerifier::class,
        'vonage' => \Kwidoo\SmsVerification\Verifiers\VonageVerifier::class,
    ],
    'default' => 'twilio',
    'round_robin' => [
        'verifiers' => ['twilio', 'vonage'],
        'current_verifier_cache_key' => 'round_robin_verifiers_',
        'verifier_for_number_cache_key' => 'round_robin_verifier_for_',
    ],

    'vonage' => [
        'api_key' => env('VONAGE_API_KEY'),
        'api_secret' => env('VONAGE_API_SECRET'),
        'brand' => env('VONAGE_BRAND', 'MyApp'),
    ],
    'twilio' => [
        'sid' => env('TWILIO_SID'),
        'auth_token' => env('TWILIO_AUTH_TOKEN'),
        'verify_sid' => env('TWILIO_VERIFY_SID'),
    ],
];
```

- **`default`**: Indicates the default SMS provider if one is not explicitly specified.
- **`round_robin`**: An array of provider keys to use in a rotating fashion when `RoundRobinVerifier` is requested.
- **`round_robin_cache_key`**: Cache key used to persist the index in the round-robin cycle.
- **`twilio`, `vonage`**: Provider-specific credentials and settings.

---

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

If you only want to use **one** provider (e.g., Twilio) for all verifications:

1. **Set** `'default' => 'twilio'` in `sms-verification.php`.
2. In your code, you can do something like:

    ```
    use Kwidoo\SmsVerification\VerifierFactory;

    class SomeController extends Controller
    {
        public function sendCode(Request $request, VerifierFactory $factory)
        {
            $phoneNumber = $request->input('phone_number');
            $verifier = $factory->make(); // uses default (twilio)
            $verifier->create($phoneNumber);

            return response()->json(['status' => 'Verification code sent.']);
        }

        public function checkCode(Request $request, VerifierFactory $factory)
        {
            $phoneNumber = $request->input('phone_number');
            $code = $request->input('code');
            $verifier = $factory->make(); // uses default (twilio)

            if ($verifier->validate([$phoneNumber, $code])) {
                return response()->json(['status' => 'Code is valid!']);
            }

            // If invalid, handle appropriately
            return response()->json(['error' => 'Invalid code'], 422);
        }
    }
    ```

### Round Robin Usage

[](#round-robin-usage)

If you want to **rotate** between providers (e.g., Twilio → Vonage → Twilio → Vonage…), you can request the *round-robin* verifier:

1. **`round_robin`** is an array of strings referencing your verifiers: `['twilio', 'vonage']`.
2. In your code, you might do:

    ```
    use Kwidoo\SmsVerification\VerifierFactory;

    class SomeController extends Controller
    {
        public function sendCode(Request $request, VerifierFactory $factory)
        {
            $phoneNumber = $request->input('phone_number');
            $verifier = $factory->make('roundRobin');
            $verifier->create($phoneNumber);

            return response()->json(['status' => 'Verification code sent.']);
        }

        public function checkCode(Request $request, VerifierFactory $factory)
        {
            $phoneNumber = $request->input('phone_number');
            $code = $request->input('code');
            $verifier = $factory->make('roundRobin');

            if ($verifier->validate([$phoneNumber, $code])) {
                return response()->json(['status' => 'Code is valid!']);
            }

            // If invalid, handle appropriately
            return response()->json(['error' => 'Invalid code'], 422);
        }
    }
    ```

The **round-robin** verifier will:

- On `create()`, pick the next provider in a cycle, send the verification code, and **remember** which provider was used for that phone number.
- On `validate()`, retrieve that same provider to check the code.

### Custom Verifiers

[](#custom-verifiers)

You can create your own SMS verifier by:

1. **Creating** a class that implements `VerifierInterface` (or extend the base `Verifier` class).
2. **Register** it in the container or simply reference its FQN in `sms-verification.verifiers`.

Example:

```
namespace App\Verifiers;

use Kwidoo\SmsVerification\Verifiers\Verifier;

class MyCustomVerifier extends Verifier
{
    public function create(string $phoneNumber): void
    {
        // Implementation to send code
    }

    public function validate(array $credentials): bool
    {
        // Implementation to check code
        return true;
    }
}
```

Then, in `sms-verification.php`:

```
'verifiers' => [
   'twilio' => \Kwidoo\SmsVerification\Verifiers\TwilioVerifier::class,
   'vonage' => \Kwidoo\SmsVerification\Verifiers\VonageVerifier::class,
   'my_custom' => \App\Verifiers\MyCustomVerifier::class,
],
```

And in code:

```
$verifier = $factory->make('my_custom');
```

---

Console Command
---------------

[](#console-command)

This package includes a console command to generate new custom verifiers from a **stub**:

```
php artisan verifier:create-sms-verifier {name?}
```

If you omit `{name}`, the command will prompt you to enter the verifier’s class name. It also asks for the client class (namespace) that the verifier should inject.

The newly generated file will be placed in `app/Verifiers/{Name}.php`. You can customize paths or logic within the command class `CreateSmsVerifier`.

---

Example Code
------------

[](#example-code)

Here’s a quick example to tie it all together:

```
// routes/api.php

use Illuminate\Support\Facades\Route;
use Kwidoo\SmsVerification\VerifierFactory;

Route::post('/send-code', function(\Illuminate\Http\Request $request, VerifierFactory $factory) {
    $phoneNumber = $request->input('phone_number');

    // If you want round robin, pass 'roundRobin' or whichever config key you want:
    // $verifier = $factory->make('roundRobin');
    $verifier = $factory->make(); // default is 'twilio'

    $verifier->create($phoneNumber);
    return response()->json(['message' => 'Code sent']);
});

Route::post('/verify-code', function(\Illuminate\Http\Request $request, VerifierFactory $factory) {
    $phoneNumber = $request->input('phone_number');
    $code = $request->input('code');

    $verifier = $factory->make(); // or 'roundRobin'
    $isValid = $verifier->validate([$phoneNumber, $code]);

    return response()->json(['valid' => $isValid]);
});
```

---

Credits
-------

[](#credits)

- **Twilio** for their robust Verify service.
- **Vonage** (formerly Nexmo) for their Verify APIs.
- **Sinch** for their SMS verification service.
- **Telnyx** for their Verify API.
- **Plivo** for their SMS verification service.
- **seven.io** for their SMS verification service.
- **Telesign** for their SMS verification service.
- **Laravel** community for a great framework to extend.

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

TODO
====

[](#todo)

- Make more round-robin strategies (e.g., Weighted Round Robin, Random, etc.).
- Implement a “fallback” approach (try one provider; if it fails, try another).
- Add tests.
- Add webhook support to better handle fails
- Add support for other SMS providers:
- Plivo
- Sinch
- [seven.io](https://www.seven.io/)
- Telesign
- ClickSend
- Textmagic
- SlickText
- Infobip
- Routee
- Telnyx

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance45

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

438d ago

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

1.0.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/40e08f40bb6cff697b1703ccab1a57f3bd327faedf429df8e588d325a76de9f8?d=identicon)[samsite](/maintainers/samsite)

---

Top Contributors

[![kwidoo](https://avatars.githubusercontent.com/u/14920653?v=4)](https://github.com/kwidoo "kwidoo (10 commits)")

---

Tags

sms verificationkwidoo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kwidoo-sms-verification/health.svg)

```
[![Health](https://phpackages.com/badges/kwidoo-sms-verification/health.svg)](https://phpackages.com/packages/kwidoo-sms-verification)
```

###  Alternatives

[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[worksome/verify-by-phone

Verify your users by call or SMS

148550.4k](/packages/worksome-verify-by-phone)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[simplesoftwareio/simple-sms

Simple-SMS is a package made for Laravel to send/receive (polling/pushing) text messages. Currently supports CalLFire, EZTexting, Email Gateways, FlowRoute, LabsMobile, Mozeo, Nexmo, Plivo, Twilio, and Zenvia

20845.7k5](/packages/simplesoftwareio-simple-sms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
