我已经在数据库中保存了一个会话,并且它有更多的一个值。所以我试图从会话中获得数量值。从laravel中的会话获取值
我的代码保存会话
public function logout(Request $request)
{
$cart_details = Cart::content();
$cart_session_test = Session::put('cart_session_test', $cart_details);
$cart_data_test = Session::get('cart_session_test');
$cart_test = [
'data' => json_encode($cart_data_test),
];
$customer_id = auth()->guard('customer_admin')->user()->id;
$carts_tbl_test = DB::table('cart_session')->where(['customer_id' => $customer_id])->first();
if(isset($carts_tbl_test))
{
DB::table('cart_session')->where(['customer_id' => $customer_id])->update($cart_test);
}else{
$cart_test['customer_id'] = $customer_id;
DB::table('cart_session')->insert($cart_test);
}
Auth::logout();
Session::flush();
return redirect()->route('login')->with('success', 'You`ve been successfully logged out');
}
当我打$ cart_test和我赞同它,我得到
阵列 ( [数据] => { “18d6934483b994fb9943b43b7d7646bf”:{ “rowId”:“18d6934483b994fb9943b43b7d7646bf”,“id”:“8”,“name”:“Product 8”,“qty”:“2”,“price”:80,“image”:“[\”hot-dog .jpg \“]”,“options”:[],“tax”:16.8,“subtotal”:160}} )
这样的话在我的登录功能,我这样做
$customer_id = auth()->guard('customer_admin')->user()->id;
$carts_tbl = DB::table('cart_session')->where(['customer_id' => $customer_id])->first();
if(isset($carts_tbl))
{
$cart_data = json_decode($carts_tbl->data);
Session::put('cart_session_test', $cart_data);
}
$show_session = Session::get('cart_session_test');
echo "<PRE>";
print_r($show_session->qty);
die();
,我得到这个错误
ErrorException在CustomersController.php线81: 未定义的属性:stdClass的:: $数量
81行是
print_r($show_session->qty);
转储'$ show_session'变量。 –
当我'DD($ show_session)'我得到'{#410▼ + “18d6934483b994fb9943b43b7d7646bf”:{#411▼ + “ROWID”: “18d6934483b994fb9943b43b7d7646bf” + “ID”: “8” + “名” :“Product 8” +“qty”:“2” +“price”:80 +“image”:“[”hot-dog.jpg“]” +“options”:[] +“tax “:16.8 +”subtotal“:160 } }' – Isis
请参阅在会话中,您正在将'qty'存储在另一个'18d6934483b994fb9943b43b7d7646bf'数组中。 –