Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Mahmoud Zalt:
Eloquent Relationships Cheat Sheet
Oct 06, 2017 @ 16:10:24

Mahmoud Zalt has a recent post to his Medium.com site that shares a cheat sheet for Eloquent relationships you can use with the Eloquent database layer in a Laravel application.

He goes through each of the relationship types and provides both a diagram showing the relationship and some sample code to make it work:

  • One to One
  • One to Many
  • Polymorphic One to Many Relationship
  • Many to Many Relationship
  • Polymorphic Many to Many Relationship

The post ends with a combined table of all of the relationships, how they connect with the other models, the number of tables involved and how to set values to a related model.

tagged: eloquent relationship cheatsheet example diagram laravel

Link: https://medium.com/@Mahmoud_Zalt/eloquent-relationships-cheat-sheet-5155498c209


Trending Topics: