mekramy/verification-code

使用缓存为Laravel生成验证码

v1.0.1 2020-04-06 06:11 UTC

This package is auto-updated.

Last update: 2024-09-06 17:23:27 UTC


README

注意:必须使用Laravel 服务容器依赖注入 创建验证码实例

$vc = app(\MEkramy\VerificationCode\VerificationCode::class);

注意(全局/私有模式):如果验证键模式设置为私有,生成的验证码仅适用于当前IP!

注意:所有方法中的最后一个参数确定验证码是全局(设置为true)还是私有(设置为false)!

创建新的验证码

要创建新的代码,需要调用 put 方法。

示例:生成名为 verify_email 的验证码,值为 12345,有效期 5 分钟

$vc->put('verify_email', '12345', 5); // Global
$vc->put('verify_email_for_current_ip_only', '45678', 5, false); // private

获取验证码

注意:如果代码已过期或不存在,get方法返回 null

$vc->get('verify_email'); # > 12345
$vc->get('not_exists'); # > null

检查验证码是否存在且未过期

$vc->exists('verify_email'); # > true
$vc->exists('not_exists'); # > false

删除验证码

$vc->remove('verify_email');
$vc->get('verify_email'); # > null
$vc->exists('verify_email'); # > false