public function checkTaskAvaliable() { $tasks_users = \App\UserTask::whereIn('status', ['active', 'available'])->get(); foreach ($tasks_users as $task_user) { $task = \App\Task::whereId($task_user->id_task)->first(); $timer = explode(':', $task->timer); $data = $task_user->created_at; $data->addHours($timer[0]); $data->addMinutes($timer[1]); if (!Carbon::now()->between($task_user->created_at, $data)) { $task_user->status = 'timeout'; $task_user->save(); } else { $data->subMinutes(9); $data2 = $data->copy(); $data2->subMinutes(1); if (Carbon::now()->between($data2, $data) && $task_user->status != 'available') { $user = \App\Users::whereId($task_user->id_user)->first(); $MESSAGE = 'You have less than 10 minutes to complete the task'; $url = 'https://api.parse.com/1/push'; $data = array('where' => ['email' => ['$in' => [$user->email]]], 'data' => array('alert' => $task->name, 'title' => $MESSAGE)); $_data = json_encode($data); $headers = array('X-Parse-Application-Id: ' . $this->APPLICATION_ID, 'X-Parse-REST-API-Key: ' . $this->REST_API_KEY, 'Content-Type: application/json', 'Content-Length: ' . strlen($_data)); $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $_data); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curl); } } } return $this; }