where('student_portal_log_id', $userId) ->orWhere('id', $userId) ->orWhere('student_id', $userId) ->first(); if (!$student) { return view('mycourse', [ 'courses' => collect([]), 'student' => null ]); } $courses = DB::table('courses') ->join('course_assign_student', 'courses.id', '=', 'course_assign_student.course_id') ->whereIn('course_assign_student.student_id', [ $student->id, $student->student_id, $student->student_portal_log_id ]) ->select('courses.*', 'course_assign_student.assigned_at') ->distinct() ->get(); return view('mycourse', compact('courses', 'student')); } public function showModule($course_id) { $course = DB::table('courses')->where('id', $course_id)->first(); if (!$course) { abort(404, 'Course not found'); } $modules = DB::table('modules') ->where('course_id', $course_id) ->get(); return view('module', compact('course', 'modules')); } }