Exemple #1
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  * @param string|null              $param
  * @return mixed
  */
 public function handle(Request $request, Closure $next, $param = null)
 {
     $routeParamName = $param ? str_plural($param) : 'id';
     if ($routeParamValue = $request->route()->getParameter($routeParamName)) {
         $request->route()->setParameter($routeParamName, optimus()->decode($routeParamValue));
     }
     return $next($request);
 }
 /**
  * Transform single resource.
  *
  * @param  \App\Tag $tag
  * @return  array
  */
 public function transform(Tag $tag)
 {
     $payload = ['id' => optimus((int) $tag->id), 'slug' => $tag->slug, 'created' => $tag->created_at->toIso8601String(), 'link' => ['rel' => 'self', 'href' => route('api.v1.tags.articles.index', $tag->slug)], 'articles' => (int) $tag->articles->count()];
     if ($fields = $this->getPartialFields()) {
         $payload = array_only($payload, $fields);
     }
     return $payload;
 }
 /**
  * Transform single resource.
  *
  * @param  \App\Attachment $attachment
  * @return  array
  */
 public function transform(Attachment $attachment)
 {
     $payload = ['id' => optimus((int) $attachment->id), 'name' => $attachment->name, 'created' => $attachment->created_at->toIso8601String(), 'link' => ['rel' => 'self', 'href' => url(sprintf('http://%s:8000/attachments/%s', config('project.app_domain'), $attachment->name))]];
     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\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\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;
 }
 /** @test */
 public function it_deletes_article()
 {
     $this->createUserStub()->login()->createArticleStub(['title' => 'foo'])->delete(route('api.v1.articles.destroy', optimus($this->article->id)), [], $this->httpHeaders($this->jwtHeader()))->seeStatusCode(StatusCode::NO_CONTENT);
 }