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

Walker's avatar

Foreach in the session

Hi, I've been worried for a long time how to get to all the data I store in a session. How could I make a foreach to attract data? I need to pull the data into a variable with each array. Thanks.

screenshot

0 likes
7 replies
neilstee's avatar

@walker can you explain a bit more what you are trying to achieve?

Is the printed data coming from your session? If so, then you already have the data? Why do you need to foreach it?

Walker's avatar

I don't know how to get that data, I would like to process it in a cycle

Walker's avatar

In me. I'm saving data to a session. I need to make a foreach over them now.

neilstee's avatar

Where do you want to foreach? On the blade file?

neilstee's avatar

@walker assuming you save it on session('users'):

@foreach(session('users') as $user)
	{{ $user->sender_first_name }}
	{{ $user->sender_last_name }}
	{{ $user->recipient_first_name }}
	{{ $user->recipient_last_name }}
@endforeach

Please or to participate in this conversation.