/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $att = Attachment::find($id); $encode = ''; if (Input::hasFile('file')) { $f = Input::file('file'); } if (Request::get('encode')) { $encode = Input::get('encode'); } $att->save(); $insert_on_db = 'NO'; if (Request::get('insert_on_db')) { $insert_on_db = Input::get('insert_on_db'); } $validator = Validator::make(Input::all(), Attachment::$RULES_CREATE); if ($validator->fails()) { return Redirect::to('admin/attachment')->withErrors($validator); } else { if ($f) { $r = array(); $file_path = public_path() . DIRECTORY_SEPARATOR . $att->upload_path . DIRECTORY_SEPARATOR . $att->name; if ($insert_on_db == 'NO') { $r = AttachmentController::uploadAttachment($f, $att); } else { if ($insert_on_db == 'SI') { $r = AttachmentController::uploadAttachmentIntoDB($f, $att); } } if ($r['valid'] && File::exists($file_path)) { File::delete($file_path); } return Redirect::to('admin/attachment'); } else { return Redirect::to('admin/attachment')->withErrors(array($f->getError(), $f->getErrorMessage())); } } }