public function toPdtContent(Request $request, $product_id) { $product = Product::find($product_id); $pdt_content = PdtContent::where('product_id', $product_id)->first(); $pdt_images = PdtImages::where('product_id', $product_id)->get(); $count = 0; $member = $request->session()->get('member', ''); if ($member != '') { $cart_items = CartItem::where('member_id', $member->id)->get(); foreach ($cart_items as $cart_item) { if ($cart_item->product_id == $product_id) { $count = $cart_item->count; break; } } } else { $bk_cart = $request->cookie('bk_cart'); $bk_cart_arr = $bk_cart != null ? explode(',', $bk_cart) : array(); foreach ($bk_cart_arr as $value) { // 一定要传引用 $index = strpos($value, ':'); if (substr($value, 0, $index) == $product_id) { $count = (int) substr($value, $index + 1); break; } } } return view('pdt_content')->with('product', $product)->with('pdt_content', $pdt_content)->with('pdt_images', $pdt_images)->with('count', $count); }
public function toProductInfo(Request $request) { $id = $request->input('id', ''); $product = Product::find($id); $product->category = Category::find($product->category_id); $pdt_content = PdtContent::where('product_id', $id)->first(); $pdt_images = PdtImages::where('product_id', $id)->get(); return view('admin.product_info')->with('product', $product)->with('pdt_content', $pdt_content)->with('pdt_images', $pdt_images); }