AnnouncementResource.php 619 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. class AnnouncementResource extends JsonResource
  5. {
  6. /**
  7. * Transform the resource into an array.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. * @return array
  11. */
  12. public function toArray($request)
  13. {
  14. $model = $this->resource;
  15. $area_name = $model->areas->name ?? '';
  16. if($model->area_id == 0){
  17. $area_name = '全部';
  18. }
  19. $data = [
  20. 'area_name' => $area_name,
  21. ];
  22. return array_merge(parent::toArray($request),$data);
  23. }
  24. }