I am implementing this shipping cart for laravel (https://github.com/darryldecode/laravelshoppingcart/issues/250). When a user logs in I would like to continue their cart, for this to happen I would need to save the session id then merge that data on login.
The problem I am having is that when i flash the cart inside \app\Http\Controllers\Auth\LoginController.php, the session id changes. It seems that all files inside Auth changes when getId().
session()->flash('guest_cart', [
'session' => session()->getId(),
'data' => cart()->getContent()
]);
So if I flash the session else where, how do I merge it into the new user cart on login if I am not able to retrieve the the original getId()?
When I output dd(session()->all()); inside LoginController it shows an empty array. I would somehow need to capture session('guest_cart.data'); during login.
I tried adding this to LoginController.php
protected function authenticated(Request $request, $user){
if(Auth::check()){
$session_id = \Session::getId();
$cartObj = \Cart::session($session_id)->getContent();
if (\Auth::guest()) {
session()->flash('guest_cart', [
'session' => $session_id,
'data' => $cartObj
]);
}
dd(session()->all());
}
but again guest_cart returns an empty array because $session_id = \Session::getId(); has changed.