In the multi-to-Multi relationship of Laravel5, In the blade template, how does one cyclically output the fields of one table and output the fields of the corresponding table

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.