key不存储在缓存laravel中

dgenwo3n  于 2021-06-07  发布在  Redis
关注(0)|答案(1)|浏览(396)

我想把钥匙藏起来

$code = mt_rand(111111, 999999);
Cache::put('notification', $code, 600);

在另一个函数中,我试着用这种方法得到那个键

if(Cache::has('notification') and Cache::get('notification') == $request->code)
   return response()->json(['status' => true, 'group' => $request->res['group']]);
else
   return response()->json(['status' => false, 'message' => 'کد اشتباه است']);

但它总是返回false

332nm8kg

332nm8kg1#

问题可能是当您使用 Cache::get() 您没有将值存储在任何位置。请尝试将其存储在变量中,并将变量与 $request->code .

$notification_cache = Cache::get('notification');
if (Cache::has('notification') and $notification_cache == $request->code)
    return response()->json(['status' => true, 'group' => $request->res['group']]);
else
    return response()->json(['status' => false, 'message' => 'کد اشتباه است']);

相关问题