Laravel how to make a leftJoin twice in one table with different parameters?

Good day,
I have the table orders stores the value of the customer_id and agent_id . I need to get their data from another table using leftJoin, but the problem is that the customer and agent is one entity (one invited the other) and need 1 query to get the data applying to a single table, example below
Order::select('order.customer_id', 'order.agent_id')
 ->leftJoin('customers', 'order.customer_id', '')
 ->leftJoin('customers', 'order.agent_id', '')
 ->where('id', $id)->first();

here is duplicated the name of the customers table, and I need to pull these values in customer.* and agent.* it is possible to add aliases?
June 7th 19 at 15:01
1 answer
June 7th 19 at 15:03
To specify an alias...

But in General why in the model the relationship is not registered to engage in such garbage?
If I have a lot of values in the table, customer_id, agent_id, country_id (about ten), it will be correct to get through with(['company', 'agent', 'country']) ? - francesco.Sporer10 commented on June 7th 19 at 15:06
Not necessarily do they load if they do not need to immediately direct.
Turning will download automatically if not loaded before.

But in General, Yes, an array to with() to load the right connections.

with() is relevant if you need to choose a lot of models(Order in your case) with their connections.
Because too much use of lazy loading the orders will be requested separately each time related records, and with them will be downloaded at once in one request for all orders. - bailee_Stant commented on June 7th 19 at 15:09

Find more questions by tags Laravel