Many to Many relation with unique records in pivot

Posted 4 years ago by francois

Hi, When you use attach() method in a many to many relation, you can add this record multiple times.

Here is an example of the pivot table

id, model1, model2

1, 10, 11

2, 10, 11

And, I'd like to forbidden this behavior.

Sync() method can't be used in my case. Thanks.

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.