DiscussionCountResource.php 939 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Models\Wbw;
  5. class DiscussionCountResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  12. */
  13. public function toArray($request)
  14. {
  15. $data = [
  16. 'id' => $this->id,
  17. 'res_id' => $this->res_id,
  18. 'res_type' => $this->res_type,
  19. 'type' => $this->type,
  20. 'editor_uid' => $this->editor_uid
  21. ];
  22. switch ($this->res_type) {
  23. case 'wbw':
  24. $wbw = Wbw::where('uid',$this->res_id)
  25. ->select(['book_id','paragraph','wid'])
  26. ->first();
  27. $data['wbw'] = $wbw;
  28. break;
  29. }
  30. return $data;
  31. }
  32. }