/** * @param $id * @param $attributes * * @return bool|mixed * * @throws \Fully\Exceptions\Validation\ValidationException */ public function update($id, $attributes) { $this->project = $this->find($id); if ($this->isValid($attributes)) { $file = null; if (isset($attributes['image'])) { $file = $attributes['image']; } //------------------------------------------------------- if ($file) { // delete old image $destinationPath = public_path() . $this->imgDir; File::delete($destinationPath . $this->project->file_name); $destinationPath = public_path() . $this->imgDir; $fileName = $file->getClientOriginalName(); $fileSize = $file->getClientSize(); $upload_success = $file->move($destinationPath, $fileName); if ($upload_success) { // resizing an uploaded file Image::make($destinationPath . $fileName)->resize($this->width, $this->height)->save($destinationPath . $fileName); // thumb Image::make($destinationPath . $fileName)->resize($this->thumbWidth, $this->thumbHeight)->save($destinationPath . 'thumb_' . $fileName); $this->project->file_name = $fileName; $this->project->file_size = $fileSize; $this->project->path = $this->imgDir; } } //------------------------------------------------------- $this->project->resluggify(); $this->project->fill($attributes)->save(); return true; } throw new ValidationException('Project validation failed', $this->getErrors()); }
/** * Update the specified resource in storage. * PUT /projects/{id} * * @param Project $project * @return Response */ public function update(Project $project) { $input = array_except(Input::all(), '_method'); $project->fill($input); if ($project->updateUniques()) { return Redirect::route('projects.show', $project->slug)->with('message', 'Project updated.'); } else { return Redirect::route('projects.edit', array_get($project->getOriginal(), 'slug'))->withInput()->withErrors($project->errors()); } }
/** * Update a project * * @param array $input * @param \Project $project * @return array */ public static function update_project($input, $project, $image) { if ($image == '') { $image = $input['old_image']; } $rules = array('name' => 'required|max:250'); $validator = \Validator::make($input, $rules); if ($validator->fails()) { return array('success' => false, 'errors' => $validator->errors); } $fill = array('name' => $input['name'], 'image' => $image, 'status' => $input['status']); $project->fill($fill); $project->save(); return array('success' => true); }
<?php # edit_task.php # 1. Logic $projects = new Projects_Collection(); $projects->where(['deleted' => '0']); $projects->where(['user_id' => AUTH::user_id()]); $projects->get(); $project = new Project(); $project->load(['slug' => Route::param('slug')]); if (Input::posted()) { $project->fill(Input::all()); $project->save(); URL::redirect('/' . $project->slug); } Sticky::set('project_name', $project->project_name); Sticky::set('project_description', $project->project_description); Sticky::set('deadline', $project->deadline); $title = 'Edit Project'; #2. Views include VIEWS . 'header.php'; include VIEWS . 'new_project.php'; include VIEWS . 'footer.php';
/** * Update a project * * @param array $input * @param \Project $project * @return array */ public static function update_project($input, $project) { $rules = array('name' => 'required|max:250'); $validator = \Validator::make($input, $rules); if ($validator->fails()) { return array('success' => false, 'errors' => $validator->errors); } $fill = array('name' => $input['name'], 'status' => $input['status'], 'default_assignee' => $input['default_assignee']); $project->fill($fill); $project->save(); return array('success' => true); }