Skip to content

Instantly share code, notes, and snippets.

@developerdino
Created September 7, 2017 05:32
Show Gist options
  • Save developerdino/65fb6e8dee90dcfb21eaadb935417ff7 to your computer and use it in GitHub Desktop.
Save developerdino/65fb6e8dee90dcfb21eaadb935417ff7 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class ArticleRelationshipResource extends Resource
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public function toArray($request)
{
return [
'author' => [
'links' => [
'self' => route('articles.relationships.author', ['article' => $this->id]),
'related' => route('articles.author', ['article' => $this->id]),
],
'data' => new AuthorIdentifierResource($this->author),
],
'comments' => (new ArticleCommentsRelationshipResource($this->comments))->additional(['article' => $this]),
];
}
public function with($request)
{
return [
'links' => [
'self' => route('articles.index'),
],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment