DetailCategoryTransformer.php 868 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-06-10
  6. * Time: 19:06
  7. */
  8. namespace App\Transformers;
  9. use League\Fractal\TransformerAbstract;
  10. use App\Models\Category;
  11. use Illuminate\Support\Carbon;
  12. class DetailCategoryTransformer extends TransformerAbstract{
  13. public function transform(Category $category)
  14. {
  15. $topic = [];
  16. foreach ($category->ct as $key=>$value){
  17. $topic[] = $value->topic;
  18. }
  19. return [
  20. 'id' => $category['id'],
  21. 'name' => $category['name'],
  22. 'img' => $category['img'],
  23. 'is_suggest' => $category['is_suggest'],
  24. 'desc' => $category['desc'],
  25. 'created_at' => Carbon::parse($category['created_at'])->toDateTimeString(),
  26. 'topic_list'=>$topic,
  27. 'topic_count'=>count($topic)
  28. ];
  29. }
  30. }