TopicDetailTransformer.php 729 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/17
  6. * Time: 18:10
  7. */
  8. namespace App\Transformers\Topic;
  9. use App\Models\Topic;
  10. use Carbon\Carbon;
  11. use League\Fractal\TransformerAbstract;
  12. class TopicDetailTransformer extends TransformerAbstract
  13. {
  14. public function __construct($uid)
  15. {
  16. $this->uid = $uid;
  17. }
  18. public function transform(Topic $topic)
  19. {
  20. return [
  21. 'id' => $topic['id'],
  22. 'name' => $topic['name'],
  23. 'img' => $topic['img'],
  24. 'follow_count' => $topic->follow->count() + (int) config('customer.add_topic_follow_count'),
  25. 'is_follow' => $topic->follow->where('uid', $this->uid)->count()?1:0,
  26. ];
  27. }
  28. }