lee-to / laravel-phone-auth
Laravel+Livewire 手机认证模块
0.5.1.6
2022-03-13 08:05 UTC
Requires
- php: ^7.3|^8.0
- doctrine/dbal: ^3.0
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="Leeto\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])
检查手机是否已确认
\Leeto\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" />