public function setAsRead($postId) { if ((int) $postId > 0 && !is_null($post = Post::find((int) $postId))) { if ($token = $post->getOwnerToken()) { $state = new StateSender($token); $state->setPostAsRead($postId); Comment::where('post_id', $postId)->get()->each(function ($comment) use($state) { $state->setCommentAsRead($comment->id); }); $state->send(); } return $this->respondNoContent(); } else { return $this->respondWithError('Post doesn\'t exist'); } }