Support the ongoing development of Laravel.io →
Laravel Session

When I receive the session variable I always receive [object Object],[object Object] I have filled the session variable from the controller, but I can not extract the values, I do not know why it always shows me the object. My code is the following public function getrooms() { $Hab = \Session::get('bookcart'); return response()->json(['Hab'=>$Hab]); }

in javascript is so

var roomadd1 = function() {
var route = "getrooms"; $.get(route, function(data){ var selec = eval(data); console.log("Este es el valor"+selec['Hab']); }); }

Last updated 3 years ago.
0

You can try this code:

public function set($key, $value) { if (is_array($value) && isset($_SESSION[$key]) && is_array($_SESSION[$key])) { $_SESSION[$key] = ArrayHelper::merge($_SESSION[$key], $value); } else { $_SESSION[$key] = $value; } } ... \Yii::$app->session->set('myvar',['subKey' => 'value']);

By:Xtreem Solution

Highly Skilled Laravel Developer

Dedicated PHP Developer

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

lucho lucheras Joined 22 Dec 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.