Answer the question
In order to leave comments, you need to log in
What is the function of table linking in Eloquent ORM Laravel?
I understand laravel ORM. I do not understand how to link tables? An analogue of joins. Let's say I have such a request
SELECT * FROM users as u left JOIN clients2adverts as c on u.id = c.id_client
left JOIN adverts as a ON c.id_adverts = a.id_realty
WHERE c.lead = 1 and u.activated = 1 or u.id_role = 2
Answer the question
In order to leave comments, you need to log in
https://laravel.com/docs/5.2/queries#joins
There is no function for linking tables in ORM, since ORM operates with objects, and their links are described in the model class and are generated automatically.
https://laravel.com/docs/5.2/eloquent-relationship...
in a model class, relationships define methods like hasMany(), hasOne(), belongsTo()
Documentation example:
belongsTo takes three parameters, the last two are optional ( needed if you want to override keys), see the EloquentORM documentation, link above.
public function user()
{
return $this->belongsTo('App\User', 'foreign_key', 'other_key');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question