As an example:
For both the project (projects) and student (students) tables, each student can have multiple projects, each of which can be done by multiple people, so add an associated table students_projects, and now I want to loop out all the students ' names and school numbers, And then you have to output the project that the student has done under each name number, and if you output a list of projects for a single student, I can get a list of the students ' projects in the controller in a similar
$roles = User::find(1)->roles way, but for the information to loop out the students, as the relevant party documentation says. and output students corresponding to the projects, how should be implemented?
Reply content:
As an example:
For both the project (projects) and student (students) tables, each student can have multiple projects, each of which can be done by multiple people, so add an associated table students_projects, and now I want to loop out all the students ' names and school numbers, And then you have to output the project that the student has done under each name number, and if you output a list of projects for a single student, I can get a list of the students ' projects in the controller in a similar $roles = User::find(1)->roles way, but for the information to loop out the students, as the relevant party documentation says. and output students corresponding to the projects, how should be implemented?
Write directly in the template
@foreach ($students as $student)
@foreach ($student->projects as $project)
<项目> {{$project->xxx}}
@endforeach
@endforeach