Skip to content
Advertisement

Laravel query join 1 table in 2 tables at single query

I have a complex query and it works, now i need to join users table and get 2 different value of it based on 2 different tables here is where things messed up.

Code

I have commented issue part as well as data that should be returned

JavaScript

Explanation:

I need to join users table to project_admins table as well as project_shoppers table and return related users to those tables.

Then I would have user 1 returned based on project_admins table And user 2 based on project_shoppers table.

Any idea how to achieve that goal?

Advertisement

Answer

Under the leftJoins you can add the extra joins for getting the users:

JavaScript

In your select you can get the details like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement