SearchHistoryTransformer.php 825 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Repositories\Transformers\Info;
  3. use App\Repositories\Models\Info\SearchHistory;
  4. use League\Fractal\TransformerAbstract;
  5. class SearchHistoryTransformer extends TransformerAbstract
  6. {
  7. /**
  8. * Prepare data to present.
  9. *
  10. * @param SearchHistory $searchHistory
  11. * @return array
  12. */
  13. public function transform(SearchHistory $searchHistory)
  14. {
  15. if (request()->has('id')) {
  16. return [
  17. 'id' => $searchHistory->id,
  18. 'created_at' => $searchHistory->created_at ? $searchHistory->created_at->format('Y-m-d H:i:s') : null,
  19. ];
  20. }
  21. return [
  22. 'id' => $searchHistory->id,
  23. 'created_at' => $searchHistory->created_at ? $searchHistory->created_at->format('Y-m-d H:i:s') : null,
  24. ];
  25. }
  26. }