public function store($input) { $files = $this->getInputFiles(); if (empty($files)) { return $this->listener->errorResponse('No input files'); } if (Input::has('type') && Input::has('id')) { $validator = Validator::make($input, ['type' => 'required', 'id' => 'required', 'path' => 'required']); $property = Input::get('property', 'assets'); if ($validator->fails()) { return $this->listener->errorResponse($validator->errors()->all()); } $type = ucfirst(Input::get('type')); $id = Input::get('id'); $item = $type::withTrashed()->whereId($id)->first(); if ($item == NULL) { return $this->statusResponse(['error' => 'No item found']); } } $validator = Validator::make($input, ['user_id' => 'required']); if ($validator->fails()) { return $this->listener->errorResponse($validator->errors()->all()); } $assets = []; foreach ($files as $f) { $asset = new Asset(); $asset->path = Input::get('path', $this->getPathForFile($f)); if (Input::has('tag')) { $asset->tag = Str::slug(strtolower(Input::get('tag'))); } if (Input::has('shared')) { $asset->shared = Input::get('shared') == 'on' ? 1 : 0; } $user = User::findFromData($input['user_id']); $asset->user()->associate($user); $asset->saveFile($f); array_push($assets, $asset); } return $this->listener->statusResponse(['notice' => 'Asset Created', 'asset' => $assets]); $replace = false; if (array_key_exists('replace', $input) && bool_val($input['replace']) === true) { $replace = true; } $rights = Input::get('rights', Asset::ASSET_RIGHTS_UNKNOWN); $photos_response = $this->addPhotosToItem($this->getInputFiles(), $item, Input::get('path'), $replace, $rights); return $this->listener->statusResponse(['notice' => 'Asset Created', 'asset' => $asset]); }
public function upload() { $wantsJson = Request::wantsJson(); $input = Input::all(); $validator = Validator::make($input, ['type' => 'required', 'id' => 'required', 'path' => 'required']); $property = Input::get('property', 'assets'); if ($validator->fails()) { return $this->errorResponse($validator->errors()->all()); } $type = ucfirst(Input::get('type')); $id = Input::get('id'); $item = $type::withTrashed()->whereId($id)->first(); if ($item == NULL) { return $this->statusResponse(['error' => 'No item found']); } $replace = false; if (array_key_exists('replace', $input) && bool_val($input['replace']) === true) { $replace = true; } $rights = Input::get('rights', Asset::ASSET_RIGHTS_UNKNOWN); $photos_response = $this->addPhotosToItem($this->getInputFiles(), $item, Input::get('path'), $replace, $rights); return $this->statusResponse(['response' => $photos_response]); }
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; }