public function handle(Navigation $navigation, Factory $validator, Dispatcher $dispatcher)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['navigationBuilder.manage'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // validate data
     $validationResult = $validator->make(array('name' => $this->name, 'data' => $this->data), Navigation::$rules);
     if ($validationResult->fails()) {
         return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400);
     }
     if (!($nav = $navigation->find($this->id))) {
         return new CommandResult(false, 'Navigation does not exist.', null, 400);
     }
     // fire before create event
     $dispatcher->fire('navigationBuilder.updating', array($nav, $this->args));
     $nav->name = $this->name;
     $nav->data = $this->data;
     $nav->save();
     // fire after create
     $dispatcher->fire('navigationBuilder.updated', array($nav, $this->args));
     // all good
     return new CommandResult(true, "Navigation successfully updated.", $nav, 200);
 }
 /**
  * @param Navigation $navigation
  * @param Factory $validator
  * @param Dispatcher $dispatcher
  * @return CommandResult
  */
 public function handle(Navigation $navigation, Factory $validator, Dispatcher $dispatcher)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['navigationBuilder.delete'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // make sure we have a navigation to delete
     if (!($nav = $navigation->find($this->id))) {
         return new CommandResult(false, "Navigation does not exist.", null, 400);
     }
     // fire before delete event
     $dispatcher->fire('navigationBuilder.deleting', array($nav, $this->args));
     // delete
     $nav->delete();
     // fire after create
     $dispatcher->fire('navigationBuilder.deleted', array($nav, $this->args));
     // all good
     return new CommandResult(true, "Navigation successfully deleted.", null, 200);
 }