/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { //$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed. $exercise = Exercise::findOrFail($id); $update = $request->all(); // is new image uploaded? if ($file = Input::file('image')) { $fileName = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/'; $destinationPath = Config::get('app.path') . $folderName; $safeName = time() . "_" . str_random(10) . '.' . $extension; $file->move($destinationPath, $safeName); //delete old pic if exists if (File::exists(Config::get('app.path') . $exercise->image)) { File::delete(Config::get('app.path') . $exercise->image); } $update['image'] = $safeName ? $folderName . $safeName : ''; } foreach (Exercise::$boolean as $field) { if (isset($update[$field]) && $update[$field] == "on") { $update[$field] = 1; } else { $update[$field] = 0; } } $exercise->update($update); return redirect('admin/exercises')->with('success', Lang::get('message.success.update')); }