NoticeTransformer.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Repositories\Transformers\Info;
  3. use App\Repositories\Models\Info\Notice;
  4. use League\Fractal\TransformerAbstract;
  5. class NoticeTransformer extends TransformerAbstract
  6. {
  7. /**
  8. * Prepare data to present.
  9. *
  10. * @param Notice $notice
  11. * @return array
  12. */
  13. public function transform(Notice $notice)
  14. {
  15. if (request()->has('id')) {
  16. return [
  17. 'id' => $notice->id,
  18. 'name' => $notice->name,
  19. 'description' => $notice->description,
  20. 'body' => $notice->body,
  21. 'release_time' => $notice->release_time,
  22. 'sort' => $notice->sort,
  23. 'status' => $notice->status,
  24. 'created_at' => $notice->created_at ? $notice->created_at->format('Y-m-d H:i:s') : null,
  25. ];
  26. }
  27. return [
  28. 'id' => $notice->id,
  29. 'name' => $notice->name,
  30. 'description' => $notice->description,
  31. 'release_time' => $notice->release_time,
  32. 'sort' => $notice->sort,
  33. 'status' => $notice->status,
  34. 'admin' => $notice->admin,
  35. 'created_at' => $notice->created_at ? $notice->created_at->format('Y-m-d H:i:s') : null,
  36. ];
  37. }
  38. }