A
A
Alex2019-02-02 17:45:18
Laravel
Alex, 2019-02-02 17:45:18

How to create a session key in laravel and save it?

Greetings.
The bottom line is this: I want to create a guestId session key for guests and write data to it.
Actually, if there is no key, then I generate it and do a put session.
But for some reason, with a new call to the code, guestId = null.
How to create a guest session in laravel?

$session_id = Session::get('guestId');

        if (!$session_id) {
            $session_id = substr(bin2hex(random_bytes(26)), 0, 26);
        }

        if (preg_match('/^[a-zA-Z0-9,\-]{22,52}$/', $session_id)) {
            Session::put('guestId',  $session_id);
        } else {
            dd('ops');
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergeyj, 2019-02-02
@sensus

Most likely, your controller or handler is not completed. Somewhere below is die / exit / dd etc ...
Therefore, the session is not saved

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question