Skip to content
Advertisement

Get orders of a user with orderItems and product details in Laravel

I have 3 tables (foods, orders and orderItems). I want to get orders of a user with orderItems and foods, but i failed.

Here’s a result what i am getting right now, but i need to get food details instead of food_id.

JavaScript

OrderController

JavaScript

User Model

JavaScript

Order Model

JavaScript

Advertisement

Answer

You should define food() method on OrderItem model.

JavaScript

And get relation data using this:

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