What is company related to?
You can eager load nested relationships like this:
$books = Book::with('author.contacts')->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm noob in Laravel and i want some help with a Query. Here is my situation. I have 4 tables:
The table user have 5 users and every user have 10 policies. The table company have 3 companies.
$user_data=User::select('*')
->with('profile','policies')
->where('id', '=', $userId)
->first();
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.
http://i.stack.imgur.com/reMtF.png
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. Thanks in advance.
Please or to participate in this conversation.