A
A
alexfyodrv2018-03-01 17:19:30
Laravel
alexfyodrv, 2018-03-01 17:19:30

Laravel how to compose leftJoin twice into same table with different parameters?

Good day,
I have the value of customer_id and agent_id in my orders table . I need to get their data from another table through leftJoin, but the problem is that customer and agent are one entity (one invited the other) and I need to get this data in 1 request by referring to one table, an example is below

Order::select('order.customer_id', 'order.agent_id')
       ->leftJoin('customers', 'order.customer_id', 'customers.id')
       ->leftJoin('customers', 'order.agent_id', 'customers.id')
       ->where('id', $id)->first();

here the name of the customers table is duplicated, and I need to pull these values ​​into customer.* and agent.* is it possible to somehow add aliases to them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-03-01
@alexfyodrv

Specify an alias...
Well, in general, why are relations not registered in the model so as not to engage in such garbage?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question