Atef95
2 months ago
217
4
Laravel

Many to Many relationship

Posted 2 months ago by Atef95

Hey guys I saw many examples about many to many relationships.. most of them use attach() method

so for example if I have Product ,Order Tables with pivot table OrderProduct..

$order=Order::find(1);
$order->products()->attach(1);

This will normally attach product 1 to order 1..

what about if I have extra fields in OrderProduct for instance " quantity" ?

how can I update it using attach() ?

Please sign in or create an account to participate in this conversation.