Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

edgreenberg's avatar

Losing session after displaying view

Laravel 5.5, session driver is 'file'

I have a set of routes wrapped in web middleware.

in ProcessForm1, I set up an array with some proposed session variables:

            $data = [
                'user_id'           => $me->UserID,
                'pin'               => $pin,
                'password_reset_id' => $pr->id,
                'username'          => $me->UserName,
                'mobile_number'     => $mobile_number,
            ];

then:

    return redirect()->to('/forgotpassword/delivery')->with($data);

When I arrive at /forgotpassword/delivery (ShowForm2) I have the session variables, and after doing nothing more than:

    $me = User::find($user_id);

    $email = $me->Email;
    $mobile = $me->MobileNumber;

I return a view:

    return view('auth.passwords.happy_reset_2', ['captcha' => $captcha, 'email' => $email, 'mobile' => $mobile]);

The view submits to processForm2 where I no longer have the session variables shown above in the data array.

Any help appreciated.

0 likes
4 replies
edgreenberg's avatar

Followup question: Does the 'with' function flash the session data in, so it is lost after one use?

bjones2015's avatar

@edgreenberg Did you make progress with this issue?

I am actually hitting the same issue now. I have session based shopping cart that is showing correctly everyone but on one page. Said page returns a view call where I am adding view with additional data.

jlrdw's avatar

This is not session, just passing an array.

            $data = [
                'user_id'           => $me->UserID,
                'pin'               => $pin,
                'password_reset_id' => $pr->id,
                'username'          => $me->UserName,
                'mobile_number'     => $mobile_number,
            ];

This is session

Session::put('dogsearch', $dogsearch);
1 like
bjones2015's avatar

Yeah after re-reading the thread, I realize I have a different issue. I'm going to make some more sanity checks and if I don't figure it out i'll make a separate question.

Please or to participate in this conversation.