2
0

SentSimResource.php 944 B

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