TestPostApiResource.php 625 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Fixtures;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. class TestPostApiResource extends JsonResource
  5. {
  6. /**
  7. * Transform the resource into an array.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. *
  11. * @return array
  12. */
  13. public function toArray($request)
  14. {
  15. return [
  16. 'id' => $this->id,
  17. 'title' => $this->title ,
  18. 'body' => $this->body,
  19. 'tags' => $this->whenLoaded('tags', function () {
  20. return TestTagApiResource::collection($this->tags);
  21. }),
  22. ];
  23. }
  24. }