/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $totalprice = 0; $user = Sentinel::getUser(); $num = $user->baskets->where('order_id', 0)->count(); $items = Basket::select(DB::raw('products.name,products.pic,baskets.id,baskets.count,baskets.unit_id,baskets.price,baskets.product_id, baskets.price*baskets.count as total'))->join('products', 'products.id', '=', 'baskets.product_id')->where('baskets.user_id', '=', $user->id)->where('baskets.order_id', 0)->get(); foreach ($items as $item) { $totalprice += $item->total; } return response()->json(['result' => true, 'count' => $num, 'cartdata' => view('cart', array('items' => $items, 'total' => $totalprice, 'unit' => Unit::all()))->render()]); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $total = 0; $user = Sentinel::getUser(); $unit = Unit::all(); $items = Basket::select(DB::raw('products.name,products.pic,baskets.id,baskets.count,baskets.unit_id,baskets.price,baskets.product_id, baskets.price*baskets.count as total'))->join('products', 'products.id', '=', 'baskets.product_id')->where('baskets.user_id', '=', $user->id)->where('baskets.order_id', 0)->get(); foreach ($items as $item) { $total += $item->total; } return view('cart.savecart', compact('items', 'total', 'user', 'unit')); }