1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/10
- * Time: 9:17
- */
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Traits\PostTrait;
- use Illuminate\Support\Carbon;
- use League\Fractal\TransformerAbstract;
- class DetailTransformer extends TransformerAbstract
- {
- use PostTrait;
- public function transform(Post $post)
- {
- $imgs = [];
- foreach($post->imgs as $img){
- $imgs[] = $img->img;
- }
- return [
- 'id' => $post['id'],
- 'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
- 'uid' => $post['uid'],
- 'username' => $post['username'],
- 'avatar' => $post['avatar'],
- 'topic' => $this->getTopic($post['topic_ids']),
- 'title' => $post['title'],
- 'content' => $post['content'],
- 'type' => $post['type'],
- 'img' => $post['img'],
- 'video' => $post['video'],
- 'imgs' => $imgs,
- 'location' => $post['location'],
- 'pv' => $post->data->pv_real.'/'.$post->data->pv,
- 'praise_count' => $post->data->praise_real_count.'/'.$post->data->praise_count,
- 'share_count' => $post->data->share_real_count.'/'.$post->data->share_count,
- 'comment_count' => $post->data->comment_count,
- 'collect_count' => $post->data->collect_real_count.'/'.$post->data->collect_count,
- 'create_bean' => $post->data->create_bean,
- 'is_suggest' => $post['is_suggest'],
- ];
- }
- }
|