- I am currently working on e commerce project. I am unable to create a session or store cart value in session below is the code snippet:
Technology Used : Php Laravel 6
namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; use App\Product; use Session; use Auth; class CartController extends Controller { public function addedtocart(Request $request){ $id=$request->proid; $quantity=$request->quantity; $product = Product::find($id); $cart = $request->session()->get('cart'); if(isset($cart[$product['Product_ID']])): $cart[$product['Product_ID']]['qty'] += $quantity; else: $cart[$product['Product_ID']] = $product; $cart[$product['Product_ID']]['qty'] = $quantity; endif; Session::push('cart',$cart); return view('frontend.cart.addedtocart',compact('product'));
} }
Could you please anyone help to me?