DiscussionCountResource.php 962 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\Wbw;
  4. use Illuminate\Contracts\Support\Arrayable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class DiscussionCountResource 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. 'id' => $this->id,
  19. 'res_id' => $this->res_id,
  20. 'res_type' => $this->res_type,
  21. 'type' => $this->type,
  22. 'editor_uid' => $this->editor_uid,
  23. ];
  24. switch ($this->res_type) {
  25. case 'wbw':
  26. $wbw = Wbw::where('uid', $this->res_id)
  27. ->select(['book_id', 'paragraph', 'wid'])
  28. ->first();
  29. $data['wbw'] = $wbw;
  30. break;
  31. }
  32. return $data;
  33. }
  34. }