Created
September 7, 2017 05:21
-
-
Save developerdino/3c0ed299d29ff6b2602cf67b40cee028 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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