Eloquent: Relationships. Eloquent relationships are understood to be practices on the Eloquent model classes.

Eloquent: Relationships. Eloquent relationships are understood to be practices on the Eloquent model classes.

Introduction

Database tables in many cases are linked to each other. For instance, a blog post might have comments that are many an order might be pertaining to an individual whom put it. Eloquent makes handling and dealing with your relationships simple, and supports a number of common relationships:

Defining Relationships

Since relationships additionally act as effective question builders, determining relationships as practices provides effective technique chaining and querying capabilities. For instance, we might chain query that is additional on this articles relationship:

But, before diving too deep into making use of relationships, why don’t we learn to determine every type of relationship supported by Eloquent.

Anyone To One

A relationship that is one-to-one a very fundamental variety of database relationship. As an example, a person model may be related to one Phone model. To determine this relationship, we shall spot a phone technique regarding the consumer model. The phone technique should phone the hasOne method and get back its outcome. The hasOne technique can be obtained to your model through the model’s Illuminate\Database\Eloquent\Model base course:

Continue reading “Eloquent: Relationships. Eloquent relationships are understood to be practices on the Eloquent model classes.”