stidges

Experience

14,150

1 Best Reply Awards

  • Member Since 4 Years Ago
  • 238 Lessons Completed
  • 7 Favorites

19th August, 2014

stidges left a reply on Many To Many Relation With Unique Records In Pivot • 4 years ago

Yeah, a primary key MUST be unique, so if you place that on those two columns, the combination has to be unique.

stidges left a reply on Many To Many Relation With Unique Records In Pivot • 4 years ago

Yep! To really enforce the unique constraint, you could also add this:

$table->primary(['order_id', 'user_id']);

stidges left a reply on Many To Many Relation With Unique Records In Pivot • 4 years ago

When the combination should be unique, you can remove the 'id' column from the pivot table. An 'id' column is only necessary if other fields in your table can't make up a unique value. Try removing the id column and making the primary key of your table a combination of model1 and model2

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.