S
S
semki0962019-05-22 20:20:36
Laravel
semki096, 2019-05-22 20:20:36

How can I customize the 'sync' method?

I'm trying to use this method to update cart data. Everything would be fine, but the cart table is built in such a way that the product id is repeated, because the product has a color attribute. That is, this option will not work because the id is duplicated.

$arr = ['43'=>[ 'product_quantity'=>'1,'product_color'=>'red'], '43'=>[ 'product_quantity'=>'3,'product_color'=>'green']];
$cart->product()->sync($arr);

As a solution, I have the opportunity to create an id-color field, and it will already be unique. Is it possible to force this method to synchronize on the id-color field? If not, can you suggest other options?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question