Search code examples
laraveleloquentlaravel-migrations

Eloquent relations and database constraints?


since Eloquent supports relationships, would you recommend to additionally define foreign key constraints in the migrations? Why?

Thanks


Solution

  • Eloquent supports relationships, but it doesn't enforce them - that has to be done in the database itself. Databases also have a habit of outliving code. What happens when you want to use this database with some other ORM in the future?

    Defining foreign key constraints is generally considered "good design", regardless of how you end up consuming that database.