public function index()
 {
     $sections = Section::all();
     if (Auth::user()) {
         $cart = Auth::user()->cart;
     } else {
         $cart = new Collection();
         if (Session::has('cart')) {
             foreach (Session::get('cart') as $item) {
                 $elem = new Cart();
                 $elem->product_id = $item['product_id'];
                 $elem->amount = $item['qty'];
                 if (isset($item['options'])) {
                     $elem->options = $item['options'];
                 }
                 $cart->add($elem);
             }
         }
     }
     $total = 0;
     $options = new Collection();
     foreach ($cart as $item) {
         $total += $item->product->price * $item->amount;
         if ($item->options) {
             $values = explode(',', $item->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.cart', compact('sections', 'total', 'cart', 'options'));
 }
 public function show($id)
 {
     $orderDetails = OrderProduct::where('order_id', $id)->get();
     $order = Order::find($id);
     $options = new Collection();
     foreach ($orderDetails as $detail) {
         if ($detail->options) {
             $values = explode(',', $detail->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.showOrder', compact('orderDetails', 'order', 'options'));
 }
 public function deleteOptionValue($id)
 {
     OptionValue::destroy($id);
     return \Redirect()->back();
 }