PostStoreTransformer.php 886 B

123456789101112131415161718192021222324252627282930313233
  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. 'category_id' => $postStore['category_id'],
  22. 'source' => $postStore['source'],
  23. 'title' => $postStore['title'],
  24. 'content' => subtext($postStore['content'], 20),
  25. 'img' => $postStore['img'],
  26. 'is_used' => $postStore['is_used'],
  27. 'created_at' => Carbon::parse($postStore['created_at'])->toDateTimeString(),
  28. ];
  29. }
  30. }