ProgressResource.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use Illuminate\Http\Request;
  4. /**
  5. * 章节翻译进度。
  6. *
  7. * 类型取自 progress_chapters 表:progress 是 double,book / para 是整数,
  8. * 时间字段可能为 null(尚未完成)。
  9. */
  10. class ProgressResource extends BaseResource
  11. {
  12. /**
  13. * @param Request $request
  14. * @return array{
  15. * book: int,
  16. * para: int,
  17. * lang: string,
  18. * progress: float,
  19. * channel_id: string,
  20. * title: string|null,
  21. * last_chapter_completed_at: string|null,
  22. * completed_at: string|null,
  23. * updated_at: string
  24. * }
  25. */
  26. public function toArray($request): array
  27. {
  28. return [
  29. 'book' => (int) $this->book,
  30. 'para' => (int) $this->para,
  31. 'lang' => $this->lang,
  32. 'progress' => (float) $this->progress,
  33. 'channel_id' => $this->channel_id,
  34. 'title' => $this->title,
  35. 'last_chapter_completed_at' => $this->last_chapter_completed_at,
  36. 'completed_at' => $this->completed_at,
  37. 'updated_at' => $this->updated_at,
  38. ];
  39. }
  40. }