public function update($id) { $this->setPageTitle('Edit Solution'); $data = Solution::find($id); if (request()->isMethod('post')) { $input = request()->all(); $validator = Solution::validate($input); if ($validator->fails()) { request()->flash(); session()->flash('errors', $validator); } else { $image = null; # HANDLE UPLOAD if (request()->hasFile('image')) { $image = request()->file('image'); if ($image->isValid()) { $valid_ext = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; $ext = $image->getClientOriginalExtension(); if (in_array($ext, $valid_ext)) { $image->move(public_path() . '/uploads', $image->getClientOriginalName()); $input['image'] = $image->getClientOriginalName(); } } else { unset($input['image']); } } else { unset($input['image']); } if (request()->has('delete_image')) { if (is_null($image)) { $input['image'] = null; } } $solution = $data->fill($input)->save(); if ($solution) { session()->flash('message', 'Solution ' . $input['name'] . ' saved'); } } } return view()->make('solution.create', compact('data')); }
public function validate($input) { return Solution::validate($input); }