solution-forest/filament-otp-input 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

solution-forest/filament-otp-input

最新稳定版本:v2.0.2

Composer 安装命令:

composer require solution-forest/filament-otp-input

包简介

Otp input for filament

README 文档

README

Latest Version on Packagist Total Downloads PHP from Packagist Tests License

One-Time Passcode (OTP) input for Filament

filament-otp-input is a package built for Filament that provides a One-Time Passcode (OTP) input form component that offers you the ability to add the following features:

  • Customize the number of inputs
  • Perform an action after filling the code
  • Move to the next input after filling
  • Move to the previous input with backspaces

Installation

Requires PHP 8.2+, and Laravel 11.0+.

You can install the package via composer:

composer require solution-forest/filament-otp-input

Usage

Inside a form schema, you can use the Otp input like this:

use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;

public function form(Form $form): Form
{
    return $form
        ->schema([
            // ...
            OtpInput::make('otp')
                ->label('Otp'),
        ]);
}

The code above will render a otp input inside the form.

Otp input

Number inputs

If the number of entries you want is less or more than the default 4 numbers, you can change it according to the example below

use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;

public function form(Form $form): Form
{
    return $form
        ->schema([
            // ...
            OtpInput::make('otp')
                ->numberInput(6)
                ->label('Otp'),
        ]);
}

The above code creates 6 inputs for entering the OTP code.

Otp input number

Get Code

If you need to receive the code after entering it completely, proceed as in the example below

use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;

public function form(Form $form): Form
{
    return $form
        ->schema([
            // ...
            OtpInput::make('otp')
                ->numberInput(8)
                ->afterStateUpdated(function (string $state){
                    dd($state);
                    // submit form or save record
                })
                ->label('Otp'),
        ]);
}

Input type

By default, the input type is set to "number". If you need to change it to "password" or "text", you can use the following methods:

use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;

public function form(Form $form): Form
{
    return $form
        ->schema([
            // ...
            OtpInput::make('otp')
                ->password()
                // or
                ->text()
                ->label('Otp'),
        ]);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 15
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-04