PostStoreTransformer.php 830 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/6
  6. * Time: 14:08
  7. */
  8. namespace App\Transformers\Post;
  9. use App\Models\PostStore;
  10. use App\Traits\PostTrait;
  11. use Illuminate\Support\Carbon;
  12. use League\Fractal\TransformerAbstract;
  13. class PostStoreTransformer extends TransformerAbstract
  14. {
  15. use PostTrait;
  16. public function transform(PostStore $postStore)
  17. {
  18. return [
  19. 'id' => $postStore['id'],
  20. 'type' => $postStore['type'],
  21. 'source' => $postStore['source'],
  22. 'title' => $postStore['title'],
  23. 'content' => subtext($postStore['content'], 20),
  24. 'img' => $postStore['img'],
  25. 'is_used' => $postStore['is_used'],
  26. 'created_at' => Carbon::parse($postStore['created_at'])->toDateTimeString(),
  27. ];
  28. }
  29. }