public function store(Request $request) { $input = $request->all(); $classroom = Classroom::withCount('students')->find($input['classroom_id']); $chosen_classrooms_ids = Classroom::where('subject_subject_id', $classroom->subject_subject_id)->pluck('id')->toArray(); if ($classroom->students_count < $classroom->attendees_limit) { $this->student->classrooms()->detach($chosen_classrooms_ids); $this->student->classrooms()->attach([$input['classroom_id'] => ['semester_id' => semester()->id]]); event(new StudentChoseClassroom(Classroom::find($input['classroom_id']), $this->student, new User())); } $classrooms = Classroom::select('cs.student_id as chosen', 'classrooms.attendees_limit', 'classrooms.name', 'classrooms.code', 'classrooms.id', 'classrooms.teacher_id', 'classrooms.subject_subject_id', 'classrooms.day', 'classrooms.hour')->join('subject_subjects as subsub', 'subsub.id', '=', 'classrooms.subject_subject_id')->join('student_subjects as stusub', function ($join) { $join->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', $this->student->id)->where('stusub.state', '=', 'study')->where('stusub.semester_id', '=', $this->semester->id); })->leftJoin('classroom_students as cs', function ($j) { $j->on('cs.classroom_id', '=', 'classrooms.id')->where('cs.student_id', '=', $this->student->id)->where('cs.semester_id', '=', semester()->id); })->whereIn('classrooms.gender', [$this->student->gender, 'b'])->with('subject')->withCount('students')->where('classrooms.subject_subject_id', $classroom->subject_subject_id)->groupBy('classrooms.id')->get(); return response()->json($classrooms, 200, [], JSON_NUMERIC_CHECK); }
public function activityedit($id) { $exam = Exam::findOrFail($id); $subjects = Subject::whereHas('teachers', function ($query) { $query->where('teacher_id', teacher()->id); })->lists('name', 'id')->toArray(); $types = config('teachers.types'); $classrooms = Classroom::where('teacher_id', teacher()->id)->inCurrentSemester()->pluck('code', 'id')->toArray(); return view('teachers::profile.activity.edit', compact('exam', 'types', 'subjects', 'classrooms')); }