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

Chrizzmeister's avatar

Store session data best practice

Hi, i have a multi-step form for my current website.

I decided to go with the Session approach of storing each step in the session, that way i can validate each step.

Since i never used this approach before, i would like to know if the following code is ok, or if it's bad practice

 session(['stepOneData' => $request->all()]);

 $testing = session('stepOneData');

when i dd() my $testing i get exactly what i need, but is it better to split up the data in smaller chunks or ?

0 likes
5 replies
Chrizzmeister's avatar

I mean using Request->all() , but thanks for the video did not watch that one yet.

the problem might be with File uploads i suppose. Should i store file uploads in the session? that seems a bad idea. Those i probably need to save to the storage first and if the user closes it browser or doesn't complete the last step i need to remove it somehow.

tomopongrac's avatar

Why dont you do validation after each step?

if i dont pass step 1 i dont wont to fill fields in step 2

Chrizzmeister's avatar

i do validate each step, that's just not including in my code example. The code shown is after i validate that step . I understand that step, i just wanted to know if using request->all() is bad, since it's all data including token information etc.

steve_laracasts's avatar

I think your session approach is fine. I mean how much data are we talking? A few Kb?

Incidentally, this is a question I have been considering too, I have to do pretty much the same thing at some point soon; my challenge is that I have to display a lot of help with each form field (textarea - probably with quite long form answers) so I was thinking of splitting my form up too.

I am almost certainly going to do this as a Vue 2 application using an API on the Laravel side for each step for complete control every step of the way. I can't quite believe I am saying this, but prior to Learning Vue 2 I would not have been looking forward to this at all, secretly I have never really liked Javascript very much, but I am actually looking forward to this.

Please or to participate in this conversation.