Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Created September 22, 2018 12:43
Show Gist options
  • Save deleugpn/98dfa66e7106f1f73f88aa7ba19f481d to your computer and use it in GitHub Desktop.
Save deleugpn/98dfa66e7106f1f73f88aa7ba19f481d to your computer and use it in GitHub Desktop.
<?php
namespace App\Modules\Authors\Resources;
use App\Modules\Books\Resources\BookResource;
use Illuminate\Http\Resources\Json\Resource;
class AuthorResource extends Resource
{
public function toArray($request)
{
return [
'id' => $this->resource->id,
'name' => $this->resource->name,
'books' => $this->whenLoaded('books', function () {
return BookResource::collection($this->resource->books);
})
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment