The Cart_product table has 4 columns:
id | cart_id | product_id | size_id | quantity
with relationship of belongsToMany
for Cart
, Product
and Size
.
User can add a product with deferent sizes but not same size, so product->id = 1 can have size->id = 1 and size->id = 2.
I want to sync product->id and size->id where only have 1 row of same product->id and size->id.
with this code, only my product->id is synced.
$this->cart->products()->syncWithoutDetaching(
[$product->id => ['size_id' => $size->id, 'quantity' => $quantity]]
);
As I said I need to sync product->id and size->id, I can have a product with deferent sizes:
id | cart_id | product_id | size_id | quantity
1 | 1 |1 | 2 |2
2 | 1 |1 | 3 |1
but not a product with same sizes:
id | cart_id | product_id | size_id | quantity
1 | 1 |1 | 2 |2
2 | 1 |1 | 2 |1
I have checked many cases as :
$this->cart->products()->syncWithoutDetaching(
[$product->id, $size->id => ['quantity' => $quantity]]
);
But it can't take true result!