events = $events; $this->posts = $posts; } /** * @param DeletePost $command * @return \Flarum\Post\Post * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(DeletePost $command) { $actor = $command->actor; $post = $this->posts->findOrFail($command->postId, $actor); $actor->assertCan('delete', $post); $this->events->dispatch( new Deleting($post, $actor, $command->data) ); $post->delete(); $this->dispatchEventsFor($post, $actor); return $post; } }