[英]How do I set a max quantity in darryldecode shopping cart in laravel?
\Cart::add(array(
'id' => $request->test,
'name' => $price->tests->item_name,
'quantity' => 1,
'price' => $price->price,
'attributes' => array(
'lab_logo' => $price->labs->logo,
'lab_name' => $price->labs->name,
'item_number' => $price->tests->item_number
),
));
When i add the same product it increments the item quantity but i want the quantity of the item to be 1 at max.当我添加相同的产品时,它会增加项目数量,但我希望项目的数量最多为 1。
According to the documentation :根据文档:
// NOTE: as you can see by default, the quantity update is relative to its current value
// if you want to just totally replace the quantity instead of incrementing or decrementing its current quantity value
// you can pass an array in quantity value like so:
Cart::update(456, array(
'quantity' => array(
'relative' => false,
'value' => 5
),
));
So, if you pass an array on add and override it to not be relative , it should work as expected:因此,如果您在 add 上传递一个数组并将其覆盖为不是relative ,它应该按预期工作:
Cart::add(array(
'id' => $request->test,
'name' => $price->tests->item_name,
'quantity' => array(
'relative' => false,
'value' => 1,
),
'price' => $price->price,
'attributes' => array(
'lab_logo' => $price->labs->logo,
'lab_name' => $price->labs->name,
'item_number' => $price->tests->item_number
),
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.