Question: How to join results from with operator in Laravel?

Question

How to join results from with operator in Laravel?

Answers 1
Added at 2017-01-02 09:01
Tags
Question

I use query builder for execution inquiries to db like as:

$result = Order::with("product", "images");

As result I get response with two nested objects inside:

{["product" : [{}], "images" : [{}]]}

How can I join these two objects to one, that to get the following response:

{"title" : "Product name", "price" : 3, "images" :{}, "order" : {} }
Answers to

How to join results from with operator in Laravel?

nr: #1 dodano: 2017-01-02 10:01

You should use nested eager loading here:

Order::with('products.images')->first();

If you want to get an array or JSON instead of collection, use toArray() or toJson() methods on collection.

Source Show
◀ Wstecz