/**
  * @param StartDiscussion $command
  * @return mixed
  */
 public function handle(StartDiscussion $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->forum->assertCan($actor, 'startDiscussion');
     // Create a new Discussion entity, persist it, and dispatch domain
     // events. Before persistance, though, fire an event to give plugins
     // an opportunity to alter the discussion entity based on data in the
     // command they may have passed through in the controller.
     $discussion = Discussion::start(array_get($data, 'attributes.title'), $actor);
     event(new DiscussionWillBeSaved($discussion, $actor, $data));
     $discussion->save();
     // Now that the discussion has been created, we can add the first post.
     // We will do this by running the PostReply command.
     try {
         $post = $this->bus->dispatch(new PostReply($discussion->id, $actor, $data));
     } catch (Exception $e) {
         $discussion->delete();
         throw $e;
     }
     // Before we dispatch events, refresh our discussion instance's
     // attributes as posting the reply will have changed some of them (e.g.
     // last_time.)
     $discussion->setRawAttributes($post->discussion->getAttributes(), true);
     $discussion->setStartPost($post);
     $this->dispatchEventsFor($discussion);
     $discussion->save();
     return $discussion;
 }
示例#2
0
 /**
  * @param CreateTag $command
  * @return Tag
  */
 public function handle(CreateTag $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->forum->assertCan($actor, 'createTag');
     $tag = Tag::build(array_get($data, 'attributes.name'), array_get($data, 'attributes.slug'), array_get($data, 'attributes.description'), array_get($data, 'attributes.color'), array_get($data, 'attributes.isHidden'));
     $tag->save();
     return $tag;
 }
 /**
  * @param CreateGroup $command
  * @return Group
  */
 public function handle(CreateGroup $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->forum->assertCan($actor, 'createGroup');
     $group = Group::build(array_get($data, 'attributes.nameSingular'), array_get($data, 'attributes.namePlural'), array_get($data, 'attributes.color'), array_get($data, 'attributes.icon'));
     event(new GroupWillBeSaved($group, $actor, $data));
     $group->save();
     $this->dispatchEventsFor($group);
     return $group;
 }