Skip to content

Instantly share code, notes, and snippets.

@developerdino
Created September 7, 2017 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developerdino/3c0ed299d29ff6b2602cf67b40cee028 to your computer and use it in GitHub Desktop.
Save developerdino/3c0ed299d29ff6b2602cf67b40cee028 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class ArticleResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public function toArray($request)
{
return [
'type' => 'articles',
'id' => (string)$this->id,
'attributes' => [
'title' => $this->title,
],
'relationships' => new ArticlesRelationshipResource($this),
'links' => [
'self' => route('articles.show', ['article' => $this->id]),
],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment