mrshanebarron/otp-input
最新稳定版本:v1.0.4
Composer 安装命令:
composer require mrshanebarron/otp-input
包简介
OTP/2FA code input component for Laravel - supports Livewire and Vue
README 文档
README
A one-time password input component for Laravel applications. Individual digit inputs for verification codes. Works with Livewire and Vue 3.
Installation
composer require mrshanebarron/otp-input
Livewire Usage
Basic Usage
<livewire:sb-otp-input wire:model="code" />
Custom Length
<livewire:sb-otp-input wire:model="code" :length="4" />
Livewire Props
| Prop | Type | Default | Description |
|---|---|---|---|
wire:model |
string | '' |
Complete OTP value |
length |
number | 6 |
Number of digits |
input-class |
string | 'border-gray-300' |
Input styling |
Vue 3 Usage
Setup
import { SbOtpInput } from './vendor/sb-otp-input'; app.component('SbOtpInput', SbOtpInput);
Basic Usage
<template> <SbOtpInput v-model="code" @complete="handleComplete" /> </template> <script setup> import { ref } from 'vue'; const code = ref(''); const handleComplete = (otp) => { console.log('OTP entered:', otp); verifyCode(otp); }; </script>
4-Digit PIN
<template> <div class="text-center"> <h2 class="text-xl font-bold mb-4">Enter PIN</h2> <SbOtpInput v-model="pin" :length="4" @complete="verifyPin" /> </div> </template>
Verification Form Example
<template> <div class="max-w-md mx-auto p-8 bg-white rounded-lg shadow"> <h2 class="text-2xl font-bold text-center mb-2">Verification</h2> <p class="text-gray-600 text-center mb-6"> Enter the 6-digit code sent to your phone </p> <SbOtpInput v-model="code" @complete="verify" input-class="border-blue-300" /> <p v-if="error" class="text-red-500 text-center mt-4">{{ error }}</p> <button @click="resend" class="w-full mt-6 text-blue-600 hover:underline text-sm" > Didn't receive code? Resend </button> </div> </template> <script setup> import { ref } from 'vue'; const code = ref(''); const error = ref(''); const verify = async (otp) => { try { await api.verifyOTP(otp); // Redirect on success } catch (e) { error.value = 'Invalid code. Please try again.'; code.value = ''; } }; const resend = async () => { await api.resendOTP(); error.value = ''; }; </script>
Vue Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue |
String | '' |
Complete OTP value |
length |
Number | 6 |
Number of input boxes |
inputClass |
String | 'border-gray-300' |
Additional input classes |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue |
string |
Value changed |
complete |
string |
All digits entered |
Keyboard Behavior
| Key | Action |
|---|---|
0-9 |
Enter digit, auto-advance |
Backspace |
Clear and go back |
← |
Move to previous input |
→ |
Move to next input |
Paste |
Auto-fill from clipboard |
Features
- Auto-Advance: Focus moves to next input automatically
- Paste Support: Paste full code to auto-fill
- Backspace Navigation: Goes to previous on empty backspace
- Arrow Keys: Navigate between inputs
- Numeric Only: Filters non-numeric characters
- Auto-Select: Selects digit on focus
- Complete Event: Fires when all digits entered
Styling
Uses Tailwind CSS:
- Large centered digits
- Focus ring highlight
- Equal-width inputs
- Customizable border color
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
- Tailwind CSS 3.x
License
MIT License
mrshanebarron/otp-input 适用场景与选型建议
mrshanebarron/otp-input 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 174 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mrshanebarron/otp-input 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrshanebarron/otp-input 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 174
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-14