SearchTitleResource.php 882 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\PaliText;
  4. use Illuminate\Contracts\Support\Arrayable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class SearchTitleResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @param Request $request
  13. * @return array|Arrayable|\JsonSerializable
  14. */
  15. public function toArray($request)
  16. {
  17. $data = [
  18. 'book' => $this->book,
  19. 'paragraph' => $this->paragraph,
  20. 'content' => $this->text,
  21. 'path' => json_decode($this->path),
  22. 'paliTitle' => $this->toc,
  23. ];
  24. $data['content'] = PaliText::where('book', $this->book)
  25. ->where('paragraph', $this->paragraph + 1)
  26. ->value('html');
  27. $data['content_type'] = 'html';
  28. return $data;
  29. }
  30. }