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

Melodia's avatar

How to store and access session values

I have a controller that saves user details into a session and it looks like this:

public function personal_store(Request $request){
    $data = [
        'name' => $request->name,
        'email' => $request->email
    ];
    Session::put('personal', $data);
    return redirect('/listing/propdetails');
}

Now I have another controller, and it I want to access the name and email stored in the session.

public function prop_store(Request $request){
    //here I want to show the name and the email
}

How can I access the name and email stored in the session?

0 likes
5 replies
kvithalani's avatar

use Session;

public function prop_store(Request $request) {

$oldCart = Session::has('personal') ? Session::get('personal') : null;

}

Snapey's avatar

errr..

Session::get('personal');

or

session('personal');
Melodia's avatar

Sorry I dont follow. All I want to do is echo a message in prop_store Something like: The name is "the name in session" and his email is "the email in session"

Yorki's avatar
Yorki
Best Answer
Level 11
public function prop_store(Request $request)
{
    $data = session('personal');
    
    echo sprintf('The name is %s and his email is %s', $data['name'], $data['email']);
}
1 like

Please or to participate in this conversation.