AdvertisementResource.php 912 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\Advertisement;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class AdvertisementResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array
  12. */
  13. public function toArray($request)
  14. {
  15. $model = $this->resource;
  16. $area_name = $model->areas->name ?? '';
  17. if($model->area_id == 0){
  18. $area_name = '全部';
  19. }
  20. $showChildren = false;
  21. if($model->advertisement_position_slug == config('systemConfig.sort.advertisement_position.config.footer.slug') && $model->pid == 0){
  22. $showChildren = true;
  23. }
  24. $data = [
  25. 'area_name' => $area_name,
  26. 'show_children' => $showChildren
  27. ];
  28. return array_merge(parent::toArray($request),$data);
  29. }
  30. }