/**
  * @param ContentTypeTaxonomy $contentTypeTaxonomy
  * @param Dispatcher $dispatcher
  * @return CommandResult
  */
 public function handle(ContentTypeTaxonomy $contentTypeTaxonomy, Dispatcher $dispatcher)
 {
     // fire before query
     $dispatcher->fire('taxonomyTerms.beforeQuery', array($this->args));
     // begin
     if (!($taxonomy = $contentTypeTaxonomy->with('terms')->find($this->taxonomyId))) {
         return new CommandResult(false, "Taxonomy not found.", null, 404);
     }
     // fire after query
     $dispatcher->fire('taxonomyTerms.afterQuery', array($this->args));
     // all good
     return new CommandResult(true, "Query terms by taxonomy command successful.", $taxonomy->terms, 200);
 }
 /**
  * @param ContentTypeTaxonomy $contentTypeTaxonomy
  * @param Dispatcher $dispatcher
  * @return CommandResult
  */
 public function handle(ContentTypeTaxonomy $contentTypeTaxonomy, Dispatcher $dispatcher)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['contentBuilder.delete'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // fire creating event
     $dispatcher->fire('taxonomy.deleting', array($this->args));
     if (!($taxonomy = $contentTypeTaxonomy->with(array('terms', 'terms.contents'))->find($this->taxonomyId))) {
         return new CommandResult(false, "Taxonomy not found.", null, 404);
     }
     // detach all contents that are related to its terms
     $taxonomy->terms->each(function ($term) {
         $term->contents()->detach();
     });
     // delete taxonomy
     $taxonomy->delete();
     // fire creating event
     $dispatcher->fire('taxonomy.deleted', array($taxonomy));
     // all good
     return new CommandResult(true, "Taxonomy successfully deleted.", null, 200);
 }