Skip to content
Advertisement

Queries in Laravel – Equivalent to left join

Currently this is my laravel query

But unfortunately, I would also like to get the connected data between the company and the user table, user_id for company and id for user

this is the table company table: enter image description here

and the user table enter image description here

How to I connect the user under the company array?

Advertisement

Answer

You need to make a relationship for the company with the user like so

Company Model

And your query will become

Now the user relationship will be inside company

OR the reverse will be User Model

Then the following query will be changed to

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