private function createFromExcel()
 {
     $semester_id = semester()->id;
     $results = Excel::load($this->filename)->get()->all();
     // dd(get_class_methods($results));
     $subjects_codes = [];
     $teachers_usernames = [];
     $classrooms_codes = [];
     foreach ($results as $sheet) {
         $item = $sheet->all();
         if (empty($item[1]) || empty($item[2]) || empty($item[3])) {
             continue;
         }
         $teachers_usernames[] = $item[2];
         $subjects_codes[] = $item[1];
         $classrooms_codes[] = $item[3];
     }
     $teachers = Teacher::whereIn('username', $teachers_usernames)->pluck('id', 'username')->toArray();
     $subjects = Subject::whereIn('code', $subjects_codes)->pluck('id', 'code')->toArray();
     $classrooms = Classroom::whereIn('code', $classrooms_codes)->inCurrentSemester()->pluck('id', 'code')->toArray();
     $new_classrooms = [];
     foreach ($results as $sheet) {
         $item = $sheet->all();
         if (empty($item[1]) || empty($item[2]) || empty($item[3])) {
             continue;
         }
         if (!isset($classrooms[$item[3]]) && isset($teachers[$item[2]]) && isset($subjects[$item[1]]) && in_array($item[5], ['m', 'f', 'b'])) {
             $new_classrooms[] = ['code' => $item[3], 'day' => $item[4] - 1, 'gender' => $item[5], 'teacher_id' => $teachers[$item[2]], 'subject_subject_id' => $subjects[$item[1]], 'semester_id' => $semester_id, 'attendees_limit' => 100, 'created_at' => new DateTime(), 'updated_at' => new DateTime()];
         }
     }
     if (!empty($new_classrooms)) {
         Classroom::insert($new_classrooms);
     }
     event(new CreateClassroomsFromExcelFinished());
 }
 public function store(SendTeacherMessageRequest $request)
 {
     $subjects_teachers = [];
     if ($request->has('subjects')) {
         $subjects_teachers = Teacher::select('id')->whereHas('subjects', function ($query) use($request) {
             $query->whereIn('subject_subjects.id', $request->input('subjects', []));
         })->pluck('id')->toArray();
     }
     $teachers_ids = array_unique(array_merge($subjects_teachers, $request->input('teachers', [])));
     $email = $request->input('email');
     $sms = $request->input('sms');
     $teachers = Teacher::whereIn('id', $teachers_ids)->get();
     $attachments = [];
     foreach ($request->file('attachment') as $attachment) {
         if (empty($attachment)) {
             continue;
         }
         $filename = uniqid() . "." . $attachment->getClientOriginalExtension();
         $attachment->move('temp/', $filename);
         $attachments[] = 'public/temp/' . $filename;
     }
     $this->dispatch(new SendTeachersMessage($teachers, $email, $sms, user()->id, $attachments));
     return redirect()->route('teachers.messages.index')->with('success', 'جاري إرسال الرسالة للمحاضرين الذين حددتهم، ستظهر الرسائل على صفحة الإدارة فور انتهاء عملية الارسال');
 }