<--!?php global $ec3; $ec3->nocss=true; ?-->
Preloader Preloader 2

Eloquent helps make controlling and working with the matchmaking effortless, and helps a number of type of dating:

Eloquent helps make controlling and working with the matchmaking effortless, and helps a number of type of dating:

Databases tables are often linked to both. For example, an article may have of a lot comments, otherwise an order might possibly be about the user whom place it.

Determining Relationships

Eloquent dating was recognized as measures on the Eloquent design groups. Once the, such as for example Eloquent designs by themselves, relationships and additionally act as strong inquire designers, determining relationships due to the fact procedures brings strong strategy chaining and you will querying opportunities. Such as for example, we could possibly chain extra restrictions about this postings relationship:

One-to-one

A-one-to-one relationship are a highly basic loved ones. Including, a user model would-be regarding the you to definitely Cellular telephone . In order to describe it relationships, we put a phone method into Affiliate design. The device means is to phone call the new hasOne approach and you may go back its result:

The first disagreement enacted toward hasOne method is title of your own related model. As relationship is placed, i ic services. Dynamic attributes allows you to accessibility dating actions because if it had been qualities discussed for the model:

Eloquent find brand new international trick of the dating based on the model title. In this situation, the telephone model is actually instantly thought to possess a person_id international secret. If you would like override that it discussion, you can even violation an extra conflict toward hasOne strategy:

Additionally, Eloquent assumes that the international trick have to have a regard complimentary the id (or perhaps the individualized $primaryKey ) column of your mother or father. To phrase it differently, Eloquent will appear into the property value the latest customer’s id line on the associate_id column of your own Phone number. If you would like the relationship to use a respect almost every other than simply id , you can solution a third conflict into hasOne strategy specifying your customized key:

Determining The newest Inverse Of one’s Relationship

Thus, we could supply the phone model from your User . Today, let us describe a relationship into Mobile phone design that can assist all of us supply an individual one is the owner of the phone. We are able to describe this new inverse away from a good hasOne relationships using the belongsTo means:

About analogy a lot more than, Eloquent will attempt to fit the user_id in the Mobile design so you can an enthusiastic id on Representative model. Eloquent find the new standard overseas key name from the tinychat bilgisayarda kullanımı examining the identity of the matchmaking means and you may suffixing the process identity that have _id . Yet not, in case your overseas trick to the Phone model is not user_id , your elizabeth given that second conflict to the belongsTo method:

In the event your moms and dad model will not use id as its primary key, or if you want to join the child model to some other line, you may also solution a third argument to your belongsTo approach indicating your own moms and dad table’s custom trick:

You to Of numerous

A-one-to-of a lot relationship is utilized to help you establish relationship in which an individual design is the owner of one number of other designs. Such as for example, an article may have an infinite number regarding statements. Like all other Eloquent matchmaking, one-to-of a lot matchmaking is actually discussed from the placing a work on your Eloquent model:

Think about, Eloquent usually automatically determine best overseas secret line into Feedback model. Because of the conference, Eloquent takes this new „serpent instance“ label of one’s purchasing design and you can suffix it which have _id . So, for this example, Eloquent commonly suppose the latest foreign key on the Remark model is actually post_id .

Since the relationships has been laid out, we could access the brand new distinct comments because of the opening the latest statements possessions. Consider, once the Eloquent will bring „dynamic services“, we could access matchmaking tips as if they were defined as qualities on the design:

Since the all the matchmaking as well as serve as ask designers, you can add then limits to which statements try recovered of the calling the new comments method and ongoing to chain criteria on the query: