function delete($id) { $this->respondTo('html', function () use($id) { $response = $this->getResponse(); $flash = $this->getSession()->getFlashBag(); try { Author::delete($id); $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index'); } catch (ResourceNotFoundException $e) { $flash->add('errors', "Cannot find Author #{$id}"); $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index'); } catch (\Exception $e) { $flash->add('errors', 'Cannot delete Author #' . $id . ' (' . $e->getMessage() . ')'); $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index'); } }); }