【问题标题】:How to view cache record in Laravel 7?如何在 Laravel 7 中查看缓存记录?
【发布时间】:2021-08-05 15:35:36
【问题描述】:

我有一堆来自使用 Laravel7 的老团队的代码。我有 2 个端点:

  • wd/request-otp(工作,OTP 在我的测试电子邮件中收到)
  • wdreq(总是说“您的 OTP 无效!”)

所以,我查了相关代码:

resource/views/emails/otp.blade.php

<p>Your OTP:<p>
<p><h1>{{$otp}}</h1></p>

WithdrawService.php

    /**
     * @param $requestOTP
     * @param $otpConfirmation
     * @throws CustomException
     */
    public function isValidOTP($requestOTP, $otpConfirmation)
    {
        if ($requestOTP !== (int) $otpConfirmation) {
            throw new CustomException('Your OTP not valid', [$requestOTP, $otpConfirmation]);
        }
    }

OTP.php

    /**
     * Create OTP number and store in the cache
     *
     * @param string $prefix
     * @param mixed $phone
     * @return integer
     */
    public function cacheTheOTP($prefix, $phone)
    {
        $OTP = rand(100000, 999999);
        Cache::put([$this->OTPKey($prefix, $phone) => $OTP], \Carbon\Carbon::now()->addMinutes(10));
        return $OTP;
    }

也许 $requestOTP 总是 != $otpConfirmation (在我的电子邮件中收到,所以我可以看到它)。所以,我需要检查一下,$requestOTP 中的值是多少,与发送到我的电子邮件的 OTP 相同吗?有没有办法检查缓存记录?我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: caching laravel-7


    【解决方案1】:
    Cache::put('key', 'value', $seconds);
    Cache::rememberForever('users', function () {
        return DB::table('users')->get();
    }); 
    Cache::get('key');
    Cache::has('key');
    Cache::pull('key');
    

    【讨论】:

    • 这个答案被标记为低质量,请提供更多支持信息和解释来更好地回答
    猜你喜欢
    • 1970-01-01
    • 2020-01-07
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 2015-12-11
    相关资源
    最近更新 更多