DetailTopicTransformer.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-06-10
  6. * Time: 18:47
  7. */
  8. namespace App\Transformers;
  9. use App\Models\Topic;
  10. use League\Fractal\TransformerAbstract;
  11. use Illuminate\Support\Carbon;
  12. class DetailTopicTransformer extends TransformerAbstract{
  13. public function transform(Topic $topic)
  14. {
  15. $category = [];
  16. foreach ($topic->ct as $key=>$value){
  17. $category[] = $value->category;
  18. }
  19. return [
  20. 'id' => $topic['id'],
  21. 'name' => $topic['name'],
  22. 'img' => $topic['img'],
  23. 'is_suggest' => $topic['is_suggest'],
  24. 'is_hot' => $topic['is_hot'],
  25. 'is_open' => $topic['is_open'],
  26. 'desc' => $topic['desc'],
  27. 'post_count' => 0,
  28. 'follow_count' => 0,
  29. 'page_count' => 0,
  30. 'created_at' => Carbon::parse($topic['created_at'])->toDateTimeString(),
  31. 'category_list'=>$category,
  32. 'circle_id'=>$topic['circle_id'],
  33. 'base_count'=>$topic['base_count'],
  34. ];
  35. }
  36. }