For example, for the tables projects and students, each student can have multiple projects and each project can be completed by multiple people, so I added another join table students_projects. Now I want to output the names and student IDs of all students in a loop...
For example:
For projects and students tables, each student can have multiple projects, and each project can be completed by multiple people, so I added another join table students_projects. Now I want to output the name and student ID of all the students cyclically, and then output the project that the student has done under each student ID, if the project list of a single student is output, as described in the related documentation
$ Roles = User: find (1)-> rolesTo obtain the project list of a student, but how can we achieve this by outputting the student information cyclically and the projects corresponding to the student?
Reply content:
For example:
For projects and students tables, each student can have multiple projects, and each project can be completed by multiple people, so I added another join table students_projects. Now I want to output the name and student ID of all the students cyclically, and then output the project that the student has done under each student ID, if the project list of a single student is output, as described in the related documentation$ Roles = User: find (1)-> rolesTo obtain the project list of a student, but how can we achieve this by outputting the student information cyclically and the projects corresponding to the student?
Directly write in the template
@ Foreach ($ students as $ student)
@ Foreach ($ student-> projects as $ project)
<Project> {$ Project-> xxx }}
@ Endforeach
@ Endforeach