/** * Transform single resource. * * @param \App\Article $article * @return array */ public function transform(Article $article) { $id = optimus((int) $article->id); $payload = ['id' => $id, 'title' => $article->title, 'content_raw' => strip_tags($article->content), 'content_html' => markdown($article->content), 'created' => $article->created_at->toIso8601String(), 'view_count' => (int) $article->view_count, 'link' => ['rel' => 'self', 'href' => route('api.v1.articles.show', $id)], 'comments' => (int) $article->comments->count(), 'author' => ['name' => $article->author->name, 'email' => $article->author->email, 'avatar' => 'http:' . gravatar_profile_url($article->author->email)], 'tags' => $article->tags->pluck('slug'), 'attachments' => (int) $article->attachments->count()]; if ($fields = $this->getPartialFields()) { $payload = array_only($payload, $fields); } return $payload; }
/** * Transform single resource. * * @param \App\User $user * @return array */ public function transform(User $user) { $id = optimus((int) $user->id); $payload = ['id' => $id, 'name' => $user->name, 'email' => $user->email, 'avatar' => 'http:' . gravatar_profile_url($user->email), 'signup' => $user->created_at->toIso8601String(), 'link' => ['rel' => 'self', 'href' => route('api.users.show', $id)], 'articles' => (int) $user->articles->count(), 'comments' => (int) $user->comments->count()]; if ($fields = $this->getPartialFields()) { $payload = array_only($payload, $fields); } return $payload; }
/** * Transform single resource. * * @param \App\Comment $comment * @return array */ public function transform(Comment $comment) { $id = optimus((int) $comment->id); $payload = ['id' => $id, 'content_raw' => strip_tags($comment->content), 'content_html' => markdown($comment->content), 'created' => $comment->created_at->toIso8601String(), 'vote' => ['up' => (int) $comment->up_count, 'down' => (int) $comment->down_count], 'link' => ['rel' => 'self', 'href' => route('api.v1.comments.show', $id)], 'author' => ['name' => $comment->author->name, 'email' => $comment->author->email, 'avatar' => 'http:' . gravatar_profile_url($comment->author->email)]]; if ($fields = $this->getPartialFields()) { $payload = array_only($payload, $fields); } return $payload; }