PHPackages                             ibrahem-kamal/laravel-otp - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. ibrahem-kamal/laravel-otp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

ibrahem-kamal/laravel-otp
=========================

generate and verify otp being sent to users

2.1.2(2y ago)0860[1 PRs](https://github.com/ibrahem-kamal/laravel-otp/pulls)MITPHPPHP ^8.2

Since Feb 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ibrahem-kamal/laravel-otp)[ Packagist](https://packagist.org/packages/ibrahem-kamal/laravel-otp)[ Docs](https://github.com/ibrahem-kamal/laravel-otp)[ GitHub Sponsors](https://github.com/ibrahemkamal)[ RSS](/packages/ibrahem-kamal-laravel-otp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (15)Used By (0)

laravel-otp
===========

[](#laravel-otp)

---

[![Latest Version on Packagist](https://camo.githubusercontent.com/7b35a68644dd2065d6b3c4fd7a285a8294eefb34ad8118036d3be17cd6055505/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6962726168656d2d6b616d616c2f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ibrahem-kamal/laravel-otp)[![GitHub Tests Action Status](https://camo.githubusercontent.com/680a5c5b7abe2a35473392d1d8c35499b669da573da08f8d713684ca6a6e8016/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6962726168656d2d6b616d616c2f6c61726176656c2d6f74702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ibrahem-kamal/laravel-otp/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ca7c851840ef12aaad1b8e1d0ed858e42eb96319c38cbe6f36ba29a3714b5a1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6962726168656d2d6b616d616c2f6c61726176656c2d6f74702f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/ibrahem-kamal/laravel-otp/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/00c8f41dfcb239b66d6329fbd35408f0a039a53259943acce2454bc7fccf2061/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6962726168656d2d6b616d616c2f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ibrahem-kamal/laravel-otp)

Laravel Otp is designed to generate and verify otp being sent to users

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

[](#installation)

You can install the package via composer:

```
composer require ibrahem-kamal/laravel-otp
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="laravel-otp-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-otp-config"
```

This is the contents of the published config file:

```
return [
    'services' => [
        'default' => [
            'expires_in' => 5, // in minutes
            'otp_generator_options' => [
                'length' => 4, // no of digits
                'numbers' => true,
                'letters' => false,
                'symbols' => false,
            ],
            'validate_uniqueness_after_generation' => true,
            'delete_after_verification' => false,
        ],
    ],
    'fallback_options' => [
        'otp_generator_options' => [
            'length' => 4, // no of digits
            'numbers' => true,
            'letters' => false,
            'symbols' => false,
        ],
        'validate_uniqueness_after_generation' => true, // whether to validate the uniqueness of the otp after generation by checking the database
        'delete_after_verification' => false, // whether to delete the otp after verification
    ]

];
```

> You can add as many services as you want, and you can use the fallback options to set the default options for the otp generation and verification

Usage
-----

[](#usage)

- First you need to prepare your model by implementing the `HasOtp` Interface and using the `InteractsWithOtp` trait

```
class User extends Authenticatable implements HasOtp
{
    use InteractsWithOtp;
}
```

> If you dont have `phone` column in your model, you can override the `getPhoneNumber` method to return the user phone number like this

```
    public function getPhoneNumber(): string
    {
        return $this->mobile_number;
    }
```

- Then you can use the `Otp` to generate otp

```
$user->otp()->generate() // returns OtpCode Model instance

// you can also pass the service name to generate otp for a specific service or modify the options

$user->otp()
        ->setPhone('11111')
        ->setValidateUniquenessAfterGeneration(false)
        ->setService('other service')
        ->setGeneratorOptions(
            length: 6,
            letters: false,
            numbers: true,
            symbols: false
        )->generate()  // returns OtpCode Model instance
```

- You can verify the otp using the `verify` method

```
$otp = $user->otp()->verifyOtp('1234') // returns ServiceResponse instance
    $otp->isSuccess(); //bool
    $otp->getErrorsString(); // errors as string
    $otp->getErrors(); // errors as array
    $otp->getData(); // OtpCode Model instance when success
    $otp->toArray(); // array of all the above
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [ibrahemkamal](https://github.com/ibrahem-kamal)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 94.2% 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 ~6 days

Recently: every ~17 days

Total

12

Last Release

759d ago

Major Versions

1.1.4 → 2.02024-03-14

PHP version history (2 changes)1.0.0PHP ^8.1

2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/033bc7c0b8c92e1771f366c5681ca9b9b5b1f81efba3046ae73ae445d3d491a2?d=identicon)[ibrahem-kamal](/maintainers/ibrahem-kamal)

---

Top Contributors

[![ibrahem-kamal](https://avatars.githubusercontent.com/u/38753243?v=4)](https://github.com/ibrahem-kamal "ibrahem-kamal (49 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellaravel otpibrahemkamal

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ibrahem-kamal-laravel-otp/health.svg)

```
[![Health](https://phpackages.com/badges/ibrahem-kamal-laravel-otp/health.svg)](https://phpackages.com/packages/ibrahem-kamal-laravel-otp)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

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