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

salioudiabate's avatar

Session

I want to store a form value Inn session when I leaves a form(pages to other)

0 likes
3 replies
bobbybouwmann's avatar

Well you should post the form to your page and store everything in the session. You can for example do that like so

public function store (Request $request)
{
    $userId = auth()->id();

    session()->put('form-' . $userId, $request->all());

    return redirect()->route('some-route');
}

Now in your next method you can retrieve this session and return it to the view

public function nextAction()
{
    $sessionData = session('form-' . auth()->id());

    return view('some-view', compact('sessionData'));
}

That should be it!

A good alternative solution for this is using localStorage on the client side. This might be a good read for you: https://stackoverflow.com/questions/38930144/keep-input-value-after-refresh-page

bobbybouwmann's avatar

@richard Great example! However if you refresh again, you will lose your data. It sounds to me that that is not a wanted case here!

1 like

Please or to participate in this conversation.