12345678910111213141516171819202122232425262728293031323334 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019-06-10
- * Time: 19:06
- */
- namespace App\Transformers;
- use League\Fractal\TransformerAbstract;
- use App\Models\Category;
- use Illuminate\Support\Carbon;
- class DetailCategoryTransformer extends TransformerAbstract{
- public function transform(Category $category)
- {
- $topic = [];
- foreach ($category->ct as $key=>$value){
- $topic[] = $value->topic;
- }
- return [
- 'id' => $category['id'],
- 'name' => $category['name'],
- 'img' => $category['img'],
- 'is_suggest' => $category['is_suggest'],
- 'desc' => $category['desc'],
- 'created_at' => Carbon::parse($category['created_at'])->toDateTimeString(),
- 'topic_list'=>$topic,
- 'topic_count'=>count($topic)
- ];
- }
- }
|