L
L
LP-DIMAN2016-01-11 12:46:01
Laravel
LP-DIMAN, 2016-01-11 12:46:01

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

How can I rewrite it using ORM?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-01-11
@LP-DIMAN

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.

N
newpy, 2016-01-11
@newpy

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 question

Ask a Question

731 491 924 answers to any question