Skip to content
Advertisement

How to make relationship between three table in laravel eloquent

I have three tables, Sections,Questions and options. Each Section has many questions and each question has many options. How can I fetch data from this tables related to each other?

Section model relationship with Question model

JavaScript

Question model relationship with Option model:

JavaScript

my query:

JavaScript

It returns this: output

I want each questions member contains options array related to it.

Advertisement

Answer

You can use nested relation in with like below.So it will fetch question options also

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