SerializeDate.php 636 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Support\Traits;
  11. use Carbon\Carbon;
  12. use DateTimeInterface;
  13. trait SerializeDate
  14. {
  15. /**
  16. * 为数组 / JSON 序列化准备日期。(Laravel 7).
  17. *
  18. * @param \DateTimeInterface $date
  19. * @return string
  20. */
  21. protected function serializeDate(DateTimeInterface $date)
  22. {
  23. return $date->format($this->dateFormat ?: Carbon::DEFAULT_TO_STRING_FORMAT);
  24. }
  25. }