PostStoreTransformer.php 788 B

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