A
A
andre77772017-04-20 07:38:15
Laravel
andre7777, 2017-04-20 07:38:15

Laravel Eloquent how to get values ​​from 3rd table?

Need help creating a
Table query:

items
-id
-order_id

orders
-id
-invoice_id

invoices
-id
-email

Purpose: Get a list of items with fields from order and from invoice
So I get with order fields how to add values ​​from invoice here before?
$items = Items::with(['order'])->get();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ramm, 2017-04-20
@andre7777

$items = Items::with(['order' => function($q){
   $q->with('invoice');
}])->get();

A
Alexey Ukolov, 2017-04-20
@alexey-m-ukolov

It's not clear what kind of structure you want to end up with, but if the solution from Ramm 's answer doesn't work for you, set up a Has Many Through relationship .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question