/** * get list of friends * * @return \App\Http\Controllers\Api\ControllerApiContact */ public function getListAvailable() { $this->_methodName = 'getListAvailable'; $this->resolveParams(); $this->checkAuth(); if (!$this->checkUserUnable() || Auth::checkAdmin()) { throw new \App\Exceptions\ExceptionApiNotFulInfo($this->_request_params, $this->_typeName, $this->_methodName); } $date = Carbon::now(); $limit = 30; if (isset($this->_request_params['beforeDate'])) { $arNeed = ['beforeDate' => 'required|date|date_format:"Y-m-d H:i:s"']; $this->checkAttr($arNeed); $date = $this->_request_params['beforeDate']; } if (isset($this->_request_params['limit'])) { $arNeed = ['limit' => 'required|integer']; $this->checkAttr($arNeed); $limit = $this->_request_params['limit']; } $tasks_user = \App\UserTask::whereStatus('available')->where('id_user', Auth::id())->take($limit)->get(); if (count($tasks_user->toArray()) == 0) { $this->_arData['data'] = []; } else { foreach ($tasks_user as $task_user) { $task = \App\Task::whereId($task_user->id_task)->first(); $this->_arData['data'][] = ['userTaskId' => (int) $task_user->id, 'taskId' => (int) $task->id, 'name' => $task->name, 'description' => $task->description, 'timer' => $task->timer, 'score' => (int) $task->point]; } } return $this; }