Home (Laravel / Eloquent) How to join 4 tables to make 1 query
Reply: 0

(Laravel / Eloquent) How to join 4 tables to make 1 query

user1028 Published in March 20, 2018, 5:28 am

I'm new at Laravel and I want some help with a Query. Here is my situation. I have 4 tables:

  • users (id, email, password.....)
  • user_profile (id, first_name, last_name,........, user_id)
  • companies (id, name,.......)
  • policies (id, policy_num, exp_date,........., user_id, company_id)

The table user have 5 users and every user have 10 policies. The table company have 3 companies.

                ->where('id', '=', $userId)

This code is working good, it retrieves the all the users and user_profile fields and all the policies(10) of this user with as you can see in this image, and I can show the user the details of the products on a home page.

I want to instead of appear the company_id from the policies table appears the name of the company from the company table. Any help is appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.372035 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO