BannerTransformer.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Repositories\Transformers\CMS;
  3. use App\Repositories\Enums\Base\BannerClickTypeEnum;
  4. use App\Repositories\Enums\Base\BannerPositionEnum;
  5. use Carbon\Carbon;
  6. use League\Fractal\TransformerAbstract;
  7. use App\Repositories\Models\CMS\Banner;
  8. /**
  9. * Class BannerTransformer.
  10. *
  11. * @package namespace App\Repositories\Transformers\CMS;
  12. */
  13. class BannerTransformer extends TransformerAbstract
  14. {
  15. /**
  16. * Transform the Banner entity.
  17. *
  18. * @param \App\Repositories\Models\CMS\Banner $model
  19. *
  20. * @return array
  21. */
  22. public function transform(Banner $model)
  23. {
  24. return [
  25. 'id' => (int)$model->id,
  26. 'name' => $model->name,
  27. 'position' => $model->position,
  28. 'position_name' => BannerPositionEnum::getDescription($model->position),
  29. 'click_type' => $model->click_type,
  30. 'click_type_text' => BannerClickTypeEnum::getDescription($model->click_type),
  31. 'click_body' => $model->click_body,
  32. 'cover' => $model->cover,
  33. 'cover_resource' => $model->cover_resource,
  34. 'start_time' => $model->start_time,
  35. 'end_time' => $model->end_time,
  36. 'sort' => $model->sort,
  37. 'status' => $model->status,
  38. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  39. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  40. ];
  41. }
  42. }