public function store($input) { $validator = Validator::make($input, Task::$rules); if ($validator->fails()) { return $this->listener ? $this->listener->errorResponse($validator->errors()->all()) : $validator->errors()->all(); } $creator_id = isset($input['creator_id']) ? $input['creator_id'] : Auth::id(); $claimed_id = isset($input['claimed_id']) ? $input['claimed_id'] : NULL; $project = Project::where('title', '=', $input['project'])->first(); // if null we need to create the new project if ($project == NULL) { $project = new Project(['title' => $input['project'], 'creator_id' => $creator_id]); $project->save(); } // does_not_expire $does_not_expire = false; if (Input::has('does_not_expire')) { $does_not_expire = bool_val($input['does_not_expire']); } $task_date = NULL; if (Input::has('task_date')) { $task_date = Carbon::createFromFormat("m/d/Y", Input::get('task_date'))->startOfDay(); } $data = ['title' => $input['title'], 'duration' => $input['duration'], 'claimed_id' => $claimed_id, 'project_id' => $project->id, 'creator_id' => $creator_id, 'details' => isset($input['details']) ? $input['details'] : NULL, 'task_date' => $does_not_expire ? NULL : $task_date, 'does_not_expire' => $does_not_expire]; $task = new Task($data); if (isset($input['created_at'])) { $task->created_at = $task->updated_at = $input['created_at']; } $task->save(); $view = NULL; // fire a new notification to the system Event::fire(Notification::NOTIFICATION_NEW_TASK, array(['object' => $task, 'name' => Notification::NOTIFICATION_NEW_TASK])); if (Input::has('view') && Input::get('view') == true) { $view = View::make('site.tasks.card', array('task' => $task, 'claimed' => false))->render(); } $id = $task->id; $task = Task::where('id', '=', $id)->with('Creator')->first(); return $this->listener ? $this->listener->statusResponse(['notice' => 'Task Created. Help is on the way!', 'task' => $task, 'view' => $view]) : $task; }