A
A
Analka2021-02-02 17:01:26
Laravel
Analka, 2021-02-02 17:01:26

How to store temporary code in Laravel?

there is a front part and api separately on Laravel

there is a functionality for sending code to the phone from the backend I

send the phone number to the backend, I generate the code, I save this code to the session

$code = rand(1000,9999);
            Session::put('sms_code', $code);
            $message = $message . $code;
            return [
                'error' => false,
                'message' => 'Код отправлен на номер телефона'
            ];


then when they enter the code from the SMS at the front and send it to the back

, there is a check and when checking it does not find the code in the session

if (Session::has('sms_code') && (int)Session::get('sms_code') == $code){
            Session::forget('sms_code');
            return [
                'error' => false
            ];
        }


in Kernel. I added a session to the api, but it doesn’t see when I knock from Postman, everything is OK, when it’s from the front, it doesn’t see

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question