/** * Adds an item to the cart * * @return Response */ public function add($product_id) { $product = Product::find($product_id); if (!$product) { abort(404); } Cart::associate('Product', 'App\\Models')->add($product_id, $product->name, 1, $product->price); return redirect()->route('cart.index'); }
/** * Execute the command. * * @return string */ public function handle() { try { $cart = Cart::associate('Product', 'App\\Repositories'); $cart->add($this->product['id'], $this->product['name'], $this->product['quantity'], $this->product['price']); event(new ProductAddedToShoppingCart()); return $this->product['id']; } catch (Exception $e) { return $e->getMessage(); } }
public function AddToCart($id, $slug) { Cart::associate('Items')->add('293ad', 'Product 1', 1, 9.99, array('size' => 'large')); $content = Cart::get('293ad'); dd($content); foreach ($content as $row) { echo 'You have ' . $row->qty . ' items of ' . $row->product->name . ' with description: "' . $row->product->description . '" in your cart.'; } }