Esempio n. 1
0
 /**
  * @param $id
  * @return arrayDelete a entity in repository by id.
  */
 public function delete($id)
 {
     try {
         $menu = $this->findById($id);
         $menu->delete();
         $related = MenuContent::where('menu_id', '=', $id)->lists('id')->toArray();
         MenuContent::where('menu_id', '=', $id)->delete();
         MenuNode::whereIn('menu_content_id', $related)->delete();
     } catch (Exception $e) {
         return ['error' => true, 'message' => trans('menu.cannot_delete'), 'response_code' => 500];
     }
     return ['error' => false, 'message' => trans('menu.article_deleted'), 'response_code' => 200];
 }
Esempio n. 2
0
 /**
  * @param MenuRequest $request
  * @param Menu $object
  * @param MenuContent $objectContent
  * @param MenuNode $objectNode
  * @param $id
  */
 public function postEdit(MenuRequest $request, Menu $object, MenuContent $objectContent, MenuNode $objectNode, $id)
 {
     $menu = $object->findOrNew($id);
     $menu->name = $request->name;
     $menu->save();
     $menuContent = $objectContent->where(['menu_id' => $menu->id])->first();
     if (!$menuContent) {
         $menuContent = new MenuContent();
         $menuContent->menu_id = $menu->id;
         $menuContent->save();
     }
     $menuNodesJson = json_decode($request->get('menu_nodes', null));
     /*Deleted nodes*/
     $deletedNodes = explode(' ', ltrim($request->get('deleted_nodes', '')));
     $objectNode->whereIn('id', $deletedNodes)->delete();
     $this->_recursiveSaveMenu($menuNodesJson, $menuContent->id, 0);
     event(new AuditHandlerEvent('Menu', 'updated', $id));
     return redirect()->route('menus.edit', $id)->with('success_msg', trans('notices.update_success_message'));
 }