PostTopicTransformer.php 724 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace App\Transformers\Post;
  3. use App\Models\Post;
  4. use App\Traits\PostTrait;
  5. use Illuminate\Support\Carbon;
  6. use League\Fractal\TransformerAbstract;
  7. class PostTopicTransformer extends TransformerAbstract
  8. {
  9. use PostTrait;
  10. public function transform(Post $post)
  11. {
  12. return [
  13. 'id' => $post['id'],
  14. 'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
  15. 'uid' => $post['uid'],
  16. 'username' => $post['username'],
  17. 'avatar' => $post['avatar'],
  18. 'topic' => $this->getTopic($post['topic_ids'], 1),
  19. 'img' => $post['img'],
  20. 'content' => subtext(strip_tags($post['content']), 200),
  21. ];
  22. }
  23. }