PHPackages                             worksome/verify-by-phone - 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. worksome/verify-by-phone

ActiveLibrary

worksome/verify-by-phone
========================

Verify your users by call or SMS

v0.6.1(2mo ago)148550.4k↑14.9%10[1 PRs](https://github.com/worksome/verify-by-phone/pulls)MITPHPPHP ^8.4CI passing

Since Dec 2Pushed 1mo ago12 watchersCompare

[ Source](https://github.com/worksome/verify-by-phone)[ Packagist](https://packagist.org/packages/worksome/verify-by-phone)[ Docs](https://github.com/worksome/verify-by-phone)[ GitHub Sponsors](https://github.com/worksome)[ RSS](/packages/worksome-verify-by-phone/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (29)Used By (0)

Verify your users by call or SMS
================================

[](#verify-your-users-by-call-or-sms)

[![Tests](https://camo.githubusercontent.com/1947473ac371c58c2ed125f38a952ddba20dcbc2e21b2b31df3615087e572fb5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f776f726b736f6d652f7665726966792d62792d70686f6e652f74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/worksome/verify-by-phone/actions/workflows/tests.yml)[![Static Analysis](https://camo.githubusercontent.com/441874b121caa1d53693d1957900d368ad793733c6294a65f6cd3915bf3f5b21/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f776f726b736f6d652f7665726966792d62792d70686f6e652f7374617469632e796d6c3f6c6162656c3d737461746963253230616e616c79736973267374796c653d666c61742d737175617265)](https://github.com/worksome/verify-by-phone/actions/workflows/static.yml)

It's a common practice: a user signs up, you send an SMS to their phone with a code, they enter that code in your application and they're off to the races.

This package makes it simple to add this capability to your Laravel application.

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

[](#installation)

You can install the package via composer:

```
composer require worksome/verify-by-phone
```

You can publish the config file by running:

```
php artisan vendor:publish --tag="verify-by-phone-config"
```

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

[](#configuration)

This package is built to support multiple verification services. The primary service is [Twilio](https://www.twilio.com/). You may configure the service in the config file at `config/verify-by-phone.php`under `driver`, or by using the dedicated `.env` variable: `VERIFY_BY_PHONE_DRIVER`.

### `twilio`

[](#twilio)

To use our Twilio integration, you'll need to provide an `account_sid`, `auth_token` and `verify_sid`. All of these can be set in the `config/verify-by-phone.php` file under `services.twilio`.

The Twilio verification channel can also be configured using the `services.twilio.channel` configuration option.

Usage
-----

[](#usage)

To use this package, you'll want to inject the `\Worksome\VerifyByPhone\Contracts\PhoneVerificationService`contract into your application. Let's imagine that you want to send the verification code in a controller method:

```
public function sendVerificationCode(Request $request, PhoneVerificationService $verificationService)
{
    // Send a verification code to the given number
    $verificationService->send(new PhoneNumber($request->input('phone')));

    return redirect(route('home'))->with('message', 'Verification code sent!');
}
```

It's as simple as that! Note that we are using `\Propaganistas\LaravelPhone\PhoneNumber` to safely parse numbers in different formats.

Now, when a user receives their verification code, you'll want to check that it is valid. Use the `verify` method for this:

```
public function verifyCode(Request $request, PhoneVerificationService $verificationService)
{
    // Verify the verification code for the given phone number
    $valid = $verificationService->verify(
        new PhoneNumber($request->input('phone')),
        $request->input('code')
    );

    if ($valid) {
        // Mark your user as valid
    }
}
```

The first parameter is the phone number (again using `\Propaganistas\LaravelPhone\PhoneNumber`), and the second is the verification code provided by the user.

Validation rule
---------------

[](#validation-rule)

We offer a rule to make it easy to verify a verification code during validation.

> Be aware that this rule will call the `verify` method of the `PhoneVerificationService` contract, and likely will make an HTTP request.

```
Validator::validate($request->all(), [
    'phone_number' => ['required'],
    'verification_code' => ['required', Rule::verificationCodeIsValid('phone_number')],
]);
```

If your data doesn't include the phone number, you may instead pass it in manually:

```
Validator::validate($request->all(), [
    'verification_code' => ['required', Rule::verificationCodeIsValid('+441174960123')],
]);
```

We extend the `Rule` class for visual consistency with other rules, but you can also use the `VerificationCodeIsValid` rule directly for better IDE support:

```
Validator::validate($request->all(), [
    'verification_code' => ['required', new VerificationCodeIsValid('+441174960123')],
]);
```

This rule will also handle the case where the verification code has expired and return a suitable error message.

Artisan commands
----------------

[](#artisan-commands)

This package ships with a couple of artisan commands that allow you to send and verify verification codes.

```
# Send a verication code to the given phone number
php artisan verify-by-phone:send "+441174960123"

# Check that a given verication code is valid for the given phone number
php artisan verify-by-phone:verify "+441174960123" 1234
```

The verify command will return a console failure if verification fails.

Testing
-------

[](#testing)

When writing tests, you likely do not want to make real requests to services such as Twilio. To support testing, we provide a `FakeVerificationService` that can be used to mock the verification service. To use it, you should set an `env` variable in your `phpunit.xml` with the following value:

```

```

Alternatively, you may manually swap out the integration in your test via using the `swap` method. The fake implementation has some useful testing methods you can use:

```
it('tests something to do with SMS verification', function () {
    $service = new FakeVerificationService();
    $this->swap(PhoneVerificationService::class, $service);

    // Customise what happens when calling `send`
    $service->sendUsing(fn () => throw new Exception('Something went wrong'));

    // Customise what happens when calling `verify`
    $service->verifyUsing(fn () => throw new Exception('Something went wrong'));

    // Throw a VerificationCodeExpiredException
    $service->actAsThoughTheVerificationCodeExpired();

    // Assert that a verification was "sent" on the given number
    $service->assertSentVerification(new PhoneNumber('+441174960123'));
});
```

You may execute this project's tests by running:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [GitHub Releases](https://github.com/worksome/verify-by-phone/releases) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Luke Downing](https://github.com/lukeraymonddowning)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~92 days

Total

18

Last Release

60d ago

PHP version history (4 changes)v0.1.0PHP ^8.0|^8.1

v0.4.0PHP ^8.2

v0.5.2PHP ^8.3

v0.5.7PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1899334?v=4)[Owen Voke](/maintainers/owenvoke)[@owenvoke](https://github.com/owenvoke)

![](https://www.gravatar.com/avatar/139db346fa173a79481af05b0455e2e8ad7d2ab594c7f53bde3522a3dfeeaf25?d=identicon)[96downlu](/maintainers/96downlu)

![](https://avatars.githubusercontent.com/u/5870441?v=4)[Oliver Nybroe](/maintainers/olivernybroe)[@olivernybroe](https://github.com/olivernybroe)

---

Top Contributors

[![lukeraymonddowning](https://avatars.githubusercontent.com/u/12202279?v=4)](https://github.com/lukeraymonddowning "lukeraymonddowning (40 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (34 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![ziming](https://avatars.githubusercontent.com/u/679513?v=4)](https://github.com/ziming "ziming (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")[![yoeriboven](https://avatars.githubusercontent.com/u/4047804?v=4)](https://github.com/yoeriboven "yoeriboven (2 commits)")[![olivernybroe](https://avatars.githubusercontent.com/u/5870441?v=4)](https://github.com/olivernybroe "olivernybroe (2 commits)")[![giggsey](https://avatars.githubusercontent.com/u/305730?v=4)](https://github.com/giggsey "giggsey (1 commits)")[![onlime](https://avatars.githubusercontent.com/u/2759561?v=4)](https://github.com/onlime "onlime (1 commits)")[![odinns](https://avatars.githubusercontent.com/u/10807424?v=4)](https://github.com/odinns "odinns (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")

---

Tags

phonesmsverificationlaravelworksomeverify-by-phone

###  Code Quality

TestsPest

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/worksome-verify-by-phone/health.svg)

```
[![Health](https://phpackages.com/badges/worksome-verify-by-phone/health.svg)](https://phpackages.com/packages/worksome-verify-by-phone)
```

###  Alternatives

[worksome/envy

Automatically keep your .env files in sync.

6871.8M](/packages/worksome-envy)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[worksome/company-info

Lookup company information

33458.3k](/packages/worksome-company-info)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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