Laravel foreach仅获取第一个值

Laravel foreach仅获取第一个值,laravel,foreach,Laravel,Foreach,我正在做一个同行评卷系统,它需要一个功能,讲师添加id列表,当学生注册课程时,他输入需要的id以匹配讲师id列表上的id 控制器 它只能匹配第一个值,但无法识别我输入的其他值。关闭重定向。很难理解该代码的上下文,但如果它与上下文不匹配,它会重定向,因此不会遍历$course\u标识符的第二个和后续值。你说得对!这是因为重定向。如果我不使用返回重定向,我应该使用什么 public function store(Request $request) { $this->validate($

我正在做一个同行评卷系统,它需要一个功能,讲师添加id列表,当学生注册课程时,他输入需要的id以匹配讲师id列表上的id

控制器


它只能匹配第一个值,但无法识别我输入的其他值。

关闭重定向。很难理解该代码的上下文,但如果它与上下文不匹配,它会重定向,因此不会遍历$course\u标识符的第二个和后续值。

你说得对!这是因为重定向。如果我不使用返回重定向,我应该使用什么
public function store(Request $request)
{
    $this->validate($request, [
        'course_code' => 'required',
        'studentid' => 'required'
    ]);

    $enrollment = new Enrollment;
    $enrollment->user_id = auth()->user()->id;
    $enrollment->course_id = $request->course;
    $enrollment->user_StudentID = $request->studentid;

    $input_course_id = $request->input('course_code');
    $input_studentid = $request->input('studentid');
    $course = Course::find($enrollment->course_id);

    $course_identifiers = $course->identifiers;

    // Need all the data in the database course table for comparison
    //$course represents the contents of the course table in all databases, then you need to loop first, then judge
    //$course stands for list $signleCourse for each piece of data

    foreach ($course_identifiers as $course_identifier) {
        //              if ($course_identifier->studentid == $input_studentid )
        if ($input_studentid == $course_identifier->studentid) {
            if ($request->course == $input_course_id) {
                //if true,save and redirect
                $enrollment->save();
                return redirect('/enrollment')->with('success', 'Course Enrolled');
            } else {
                return redirect('/enrollment')->with('error', 'Please Enter Correct Confirmation Code');
                //If false do nothing
            }
        } else {
            return redirect('/enrollment')->with('error', 'Please Enter Correct Student ID');
            //If false do nothing
        }
    }
}