1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019-06-10
- * Time: 18:47
- */
- namespace App\Transformers;
- use App\Models\Topic;
- use League\Fractal\TransformerAbstract;
- use Illuminate\Support\Carbon;
- class TopicTransformer extends TransformerAbstract{
- public function transform(Topic $topic)
- {
- $category = [];
- foreach ($topic->ct as $key=>$value){
- if($key < 3){
- $category[] = $value->category->name;
- }
- }
- return [
- 'id' => $topic['id'],
- 'name' => $topic['name'],
- 'img' => $topic['img'],
- 'is_suggest' => $topic['is_suggest'],
- 'is_hot' => $topic['is_hot'],
- 'is_open' => $topic['is_open'],
- 'desc' => $topic['desc'],
- 'post_count' => $topic['use_count'],
- 'follow_count' => $topic['follow_count'],
- 'page_count' => $topic['pv'],
- 'created_at' => Carbon::parse($topic['created_at'])->toDateTimeString(),
- 'category_list'=>$category,
- ];
- }
- }
|