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

me_macfly's avatar

session()->get( session_form_id ) Get session value in an array of the session id

Hi,

I am starting to use laravel and try to find my way around.

I have a multi step form on server side and I am saving the request() data in a session.

session()->put('session_form_id', request()->all());

This will give me a session similar to this: ( dd(session()->all() );

array:2 [▼
  "_token" => "dwBxbjD5ts5ZlHVsPu5b9vLEdp47qyHAszaGhvfl"
  "session_form_id" => array:1 [▼
    "title" => "Some Title"
  ]
]

On my blade I want to pre-fill the value of the input fields if the session has saved data for that input.

As it is in the session already, I do not need to pass the session data to the view.

In the blade I tried to use all kind of approaches but cannot find out a good solution to check and display the Title if it isset.

{{ session()->get( 'session_form_id'  )['title'] }}
{{ session()->get( 'session_form_id'['title']  ) }}
{{ session()->get( 'session_form_id', ['title']  ) }}
{{ session()->get( 'session_form_id', 'title'  ) }}

get only accept one parameter for the id.

What works is:

@php 
$data = session()->get( 'session_form_id' );
@phpend
{{ $data['title'] }}

This seems a bit for an overkill.

Do I overdue it? i still can pass the session data array directly to the view. Is there an easy way to access session data in an array like $_SESSION['session_form_id']['title']

Thank you!

0 likes
5 replies
zainudinnoori's avatar

What exactly you want, you are pushing an array of data into a session right? and now you wanna use the array of data which is in session to your view . am i correct ?

me_macfly's avatar

Yes. Is there a way to access the values of the array inside the session with any session method given by laravel?

zainudinnoori's avatar

yes you can access the array like so:

@foreach(Session::get('session_form_id') as $id)
{{$id->title}}
@endforeach
me_macfly's avatar

Thank you.

"Trying to get property of non-object" It is an array so correct would be:

@foreach(Session::get('session_form_id') as $id)
{{ $id['title'] }}
@endforeach

But isn't this a bit Laravel "unlike"? Running a foreach to get a specific known value inside a session object?

I assume the best way would be to pass the array to the blade instead of using session::get inside the blade or to save the session array into a variable inside the blade.

me_macfly's avatar
me_macfly
OP
Best Answer
Level 1

I actually found what I was looking for:

session()->get( 'session_form_id.title')
1 like

Please or to participate in this conversation.