mmaged
2 months ago
470
3
Laravel

Resent the verification code after amount of time

Posted 2 months ago by mmaged

So here is the problem, I want to give chance to resend the verification code up to 3 times, after the third chance the user also can resent the code but after an amount of time, let’s say 10 mins.

I tried with this code, but it does not work


$user = auth()->user();

if ($user->codes()->count() < 3) {
    return response('done');
}

if ($user->is_exceed) {
    $user->exceed_time = Carbon::parse(Carbon::now()->toDateTimeString())->format(‘I’);
    $user->is_exceed = false;
    $user->save();
}

$time_difference = abs($user->exceed_time - Carbon::parse(Carbon::now()->toDateTimeString())->format(‘I’))
;
if ($time_difference >= 10) {
    Code::where('user_id', $user->id)->delete();
}

return response(‘try after 10 mins’);


Please sign in or create an account to participate in this conversation.