public function update($id) { $flash = $this->getSession()->getFlashBag(); $request = $this->getRequest(); try { $product = Product::update($id, $request->getParams()); $this->respondTo('html', function () use($id) { $this->getResponse()->redirect('App\\Admin\\Controllers\\ProductController', 'edit', [$id]); }); } catch (ResourceNotFoundException $e) { $flash->set('inputs', $request->getParams()->all()); $this->respondTo('html', function () use($id) { $this->getResponse()->redirect('App\\Admin\\Controllers\\ProductController', 'edit', [$id]); }); } catch (ValidationException $e) { $flash->set('errors', $e->getErrors()); $flash->set('inputs', $request->getParams()->all()); $this->respondTo('html', function () use($id) { $this->getResponse()->redirect('App\\Admin\\Controllers\\ProductController', 'edit', [$id]); }); } }