DavidPetrov
4 months ago

Populating default pivot attributes by one of the related models

Posted 4 months ago by DavidPetrov

Situation is the following: I've got two tables: orders and articles which are many to many related. I'm using a custom pivot model OrderArticlePivot as described in the documentation. My pivot table has custom attributes: count, price, time. Same attributes are present in the articles table. I'd really like to somehow tell my custom pivot model to inherit those attributes from the Article instance being attached to an order without having to everytime pass the attributes to the attach() method. Is there any way of achieving that? The documentation on custom pivot models is really brief and I couldn't find anything on the topic. Thanks!

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