COACHTHEM
2 years ago
904
5
Laravel

session not working in laravel 5.5

Posted 2 years ago by COACHTHEM

I am trying to set details of user in the session using global helper function session() . after setting session using session(['user' => ['id'=>1,'name'=>'my name']]); I am trying to access the user array from session on a different page like this $user_details = session('user'); Unfortunately I am not able to print the array. Below is my code

    public function index()
    {
        session(['user' => ['id'=>1,'name'=>'my name']]);
    }

    public function test()
    {
        $user_details = session('user');
        print_r($user_details);
    }

Please sign in or create an account to participate in this conversation.