ert3e / laravel-phone-auth
Laravel+livewire 手机认证模块
0.1
2022-04-18 04:58 UTC
Requires
- php: ^7.3|^8.0
- doctrine/dbal: ^2.13.7
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: 8.5.x-dev
README
重要
- 需要 laravel livewire 包
- 默认模板使用 tailwind 类(如需自定义,请进行修改)
安装
-
安装 livewire
-
安装 doctrine/dbal
-
composer require lee-to/laravel-phone-auth
-
php artisan vendor:publish --provider="Ert3e\PhoneAuth\Providers\PhoneAuthServiceProvider"
-
配置 config/phone_auth.php
用法
用户模型
- 将 PhoneVerification 特性添加到用户模型
use PhoneVerification;
- 将电话属性添加到用户模型
protected $casts = [ 'phone' => PhoneCast::class ];
Blade 组件
认证/电话验证表单
- 简单
@livewire('phone-verification')
- 无表单包裹
@livewire('phone-verification', ['formWrap' => false])
- 注册新用户或登录,如果电话已验证且存在
@livewire('phone-verification', ['loginAndRegister' => true])
检查电话是否已确认
\Ert3e\PhoneAuth\Models\ConfirmedPhone::confirmed($phone, $user_id = null);
组件属性(覆盖配置)
- stopEvents (bool) = 关闭 emitBefore, emitAfter
- customRedirectTo (bool|array) = 成功后重定向
- emptyCustomFields (bool) = 禁用自定义字段
- customParams (array) = 向视图发送自定义属性
<livewire:phone-verification :stopEvents="true" :customRedirectTo="'/'" :emptyCustomFields="true" :customParams="['btn' => 'Login', 'title' => 'Login']" :formWrap="false" :loginAndRegister="true" />