/** * Update the specified theme in storage. * * @param int $id * @return Response */ public function update($id) { $theme = Theme::findOrFail($id); $rules = array('name' => 'required', 'description' => 'required', 'thumbnail' => 'image', 'powerful_id' => 'required', 'category_id' => 'required'); $validator = Validator::make($data = Input::except('images'), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } /** * Convert list id powerful to json */ $data['powerful_id'] = json_encode($data['powerful_id']); /** * Upload new theme thunbnail */ if (Input::hasFile('thumbnail')) { //remove old theme thumbnail if (File::exists($theme->thumbnail)) { File::delete($theme->thumbnail); } //create new theme thumbnail $tb_name = md5(time() . Input::file('thumbnail')->getClientOriginalName()) . '.' . Input::file('thumbnail')->getClientOriginalExtension(); Input::file('thumbnail')->move($this->path, $tb_name); $tb_path = $this->path . '/' . $tb_name; $data['thumbnail'] = $tb_path; } else { unset($data['thumbnail']); } //create new theme $theme->update($data); //update list old theme images if (Input::has('theme_images')) { $theme_images = Input::get('theme_images'); foreach ($theme_images as $key => $image) { $themeimage = ThemeImage::find($key); $idata = array('image' => $image['url'], 'name' => $image['name']); $themeimage->update($idata); } } //create new theme images if (Input::has('new_theme_images')) { $theme_images = Input::get('new_theme_images'); foreach ($theme_images as $image) { $idata = array('image' => $image['url'], 'name' => $image['name'], 'theme_id' => $theme->id); ThemeImage::create($idata); } } //update theme change logs if (Input::has('changelogs')) { $cdata = array('description' => Input::get('changelogs'), 'theme_id' => $theme->id, 'changed_date' => new Datetime()); ThemeLog::create($cdata); } return Redirect::route('admin.themes.index')->with('message', 'Item had updated!'); }