In my Laravel project, I am trying to display some data from the database. The data is looked up from multiple tables. The structure looks like this:
-
Group ( e.g. name = "G1")
- Book ( e.g. name = "B1")
- Pencil (e.g. name = "P1")
- Ink (e.g. name = "I1")
-
Group (e.g. name = "G2")
- Book ( e.g. name = "B2")
- Pencil (e.g. name = "P2")
- Ink (e.g. name = "I2")
Group, Book, Pencil & Ink are Eloquent/Model classes. I can lookup the data fine (with all the relationship between the tables). Now, I want to send this data to the Laravel view php, so that it can be displayed. At the view php, there will be drop-down element for Group with group name (e.g. "G1" or "G2") displayed, so if the user select "G1", the page should display all the G1 related info (e.g. B1, P1, I1) and for "G1", it's related info. By default (or on page load), first group in the list and its related info should be displayed.
I want to know how should I pack the data (I believe is some array) and use it in view php? And also how to update the view when the selection has changed in the Group dropdown?
Many Thanks!