Model Relationship to Itself
Laravel provides a nice and easy way to build model relationship using some methods like hasOne(), hasMany(), belongsTo() and belongsToMany() and each one of these methods are used for different kinds of relationships, for example, hasOne() used for one to one relationship and hasMany() for one to many and so on. These methods let use build a relationship among models. Model relationship is useful for retrieving or saving/updating related models (database records) from or to the database. These relationships allow us to save or select related data to/from database very easily without writing complex queries manually, instead, Laravel’s powerful Eloquent ORM does the job for us using those pre-defined relationship.
Link:
This post is submitted by our members. Submit a new post.
Tags: v4.x