/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $columns = ['users.device_token', 'study_sessions.title', 'study_sessions.time_start', 'study_sessions.location', 'study_sessions.going_count', 'users.cruz_id', 'classes.class_name'];
     $justPassed = StudySession::join('user_classes', 'user_classes.class_id', '=', 'study_sessions.class_id')->join('users', 'user_classes.user_id', '=', 'users.id')->join('classes', 'classes.id', '=', 'user_classes.class_id')->where('user_classes.priority', '1')->where('study_sessions.id', $this->studySession->id)->select($columns)->get();
     $devs = [];
     foreach ($justPassed as $user) {
         $devs[] = PushNotification::Device($user->device_token);
     }
     $readableTime = date('g:i A', strtotime($user->time_start));
     $message = PushNotification::Message('There is a new ' . $user->class_name . ' session starting at ' . $readableTime . ' in ' . $user->location . '.');
     $collection = PushNotification::app('StudyCorner')->to(PushNotification::DeviceCollection($devs))->send($message);
 }
 public function changeStatus(Request $request)
 {
     //user_id is autoincrement
     $data = $request->all();
     $info = ['user_id' => $data['user_id'], 'session_id' => $data['session_id'], 'status' => $data['status']];
     if (UserSessions::where('user_id', $info['user_id'])->where('session_id', $info['session_id'])->count() == 0) {
         $userSession = UserSessions::create($info);
         $changeCount = StudySession::where('id', '=', $info['session_id'])->increment('going_count');
     } else {
         if ($info['status'] == 1) {
             $changeCount = StudySession::where('id', '=', $info['session_id'])->increment('going_count');
         } else {
             $changeCount = StudySession::where('id', '=', $info['session_id'])->decrement('going_count');
         }
         UserSessions::where('user_id', $info['user_id'])->where('session_id', $info['session_id'])->update(['status' => $info['status']]);
     }
     $user = User::find($info['user_id']);
     return response()->json(['success' => 'true', 'cruz_id' => $user->cruz_id]);
 }