InformationTransformer.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repositories\Transformers\Inform;
  3. use Carbon\Carbon;
  4. use League\Fractal\TransformerAbstract;
  5. use App\Repositories\Models\Inform\Information;
  6. /**
  7. * Class InformationTransformer.
  8. *
  9. * @package namespace App\Repositories\Transformers\Inform;
  10. */
  11. class InformationTransformer extends TransformerAbstract
  12. {
  13. /**
  14. * Transform the Information entity.
  15. *
  16. * @param \App\Repositories\Models\Inform\Information $model
  17. *
  18. * @return array
  19. */
  20. public function transform(Information $model)
  21. {
  22. return [
  23. 'id' => (int)$model->id,
  24. 'title' => $model->title,
  25. 'category_id' => $model->category_id,
  26. 'category_name' => $model->category ? $model->category->name : '--',
  27. 'cover' => $model->cover,
  28. 'cover_resource' => $model->cover_resource,
  29. 'short_description' => $model->short_description,
  30. 'tags' => $model->tags,
  31. 'slug' => $model->slug,
  32. 'body' => $model->body,
  33. 'published_at' => $model->published_at,
  34. 'is_message' => $model->is_message,
  35. 'view_count' => $model->view_count,
  36. 'good_count' => $model->good_count,
  37. 'sort' => $model->sort,
  38. 'status' => $model->status,
  39. 'admin_name' => $model->admin->name,
  40. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  41. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  42. ];
  43. }
  44. }