SentSimResource.php 957 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Http\Controllers\CorpusController;
  4. use App\Models\PaliSentence;
  5. use Illuminate\Contracts\Support\Arrayable;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Resources\Json\JsonResource;
  8. class SentSimResource extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @param Request $request
  14. * @return array|Arrayable|\JsonSerializable
  15. */
  16. public function toArray($request)
  17. {
  18. // 获取实际句子信息
  19. $sent = PaliSentence::find($this->sent2);
  20. $channels = explode(',', $request->input('channels'));
  21. $mode = $request->input('mode', 'read');
  22. $sentId = $sent->book.'-'.$sent->paragraph.'-'.$sent->word_begin.'-'.$sent->word_end;
  23. $Sent = new CorpusController;
  24. $tpl =
  25. $data['sent'] = $Sent->getSentTpl($sentId, $channels, $mode);
  26. $data['sim'] = $this->sim;
  27. return $data;
  28. }
  29. }