Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (31 sloc) 987 Bytes
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
use function sprintf;
class ArticleResource extends JsonResource
{
public static $wrap = '';
public function toArray($request): array
{
return [
'id' => $this->resource['id'],
'title' => $this->resource['title'],
'_embedded' => [
'comments' => new CommentResourceCollection(
new Collection($this->resource['comments'])
),
'user' => new UserResource([
'user_id' => $this->resource['user_id'],
'user_name' => $this->resource['user_name']
]),
],
'_links' => [
'self' => [
'href' => sprintf('/articles/%s', $this->resource['id'])
]
]
];
}
}
You can’t perform that action at this time.