Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Created August 26, 2017 17:28
Show Gist options
  • Save deleugpn/426632ef64f80ad9387863d131364562 to your computer and use it in GitHub Desktop.
Save deleugpn/426632ef64f80ad9387863d131364562 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class UsersResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'name' => $this->name,
'email' => $this->email,
'posts' => PostsResource::collection($this->whenLoaded('posts'))
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment