示例#1
0
 /**
  * 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'));
 }
示例#2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Basket $basket, Request $request)
 {
     if ($basket->delete()) {
         if ($request->ajax()) {
             return response()->json(['delid' => $basket->id]);
         } else {
             return redirect()->home()->with('success', 'محصول از سبد خرید حذف شد.');
         }
     }
     if ($request->ajax()) {
         return response()->json(['result' => false]);
     } else {
         return redirect()->home()->with('fail', 'خطا در اتصال به پایگاه داده.');
     }
 }